# Same random value as result in code. How do I get different random values?

**URL:** <https://verificationacademy.com/forums/t/same-random-value-as-result-in-code-how-do-i-get-different-random-values/32935>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, systemverilog-randomization\
**Created:** [March 5, 2017, 4:26am UTC](https://verificationacademy.com/forums/t/same-random-value-as-result-in-code-how-do-i-get-different-random-values/32935 "2017-03-05T04:26:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sbellock](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@sbellock](https://verificationacademy.com/forums/u/sbellock)\
**Post date:** [March 5, 2017, 3:03pm UTC](https://verificationacademy.com/forums/t/same-random-value-as-result-in-code-how-do-i-get-different-random-values/32935/2 "2017-03-05T15:03:49Z")

</div>

_In reply to [murthy1993](https://verificationacademy.com/forums/t/same-random-value-as-result-in-code-how-do-i-get-different-random-values/32935):_

If the randomize method succeeds then it returns a value of 1, else it returns a value of 0. In your code you are displaying the return value of the randomize method, not the randomized variable. To do that you want to access tt1.val1. It is also considered good practice to check the randomize method’s return value in case randomization fails:

```verilog
if (!tt1.randomize) $error("Unable to randomize tt1.");

```

---

_[View the full topic](https://verificationacademy.com/forums/t/same-random-value-as-result-in-code-how-do-i-get-different-random-values/32935)._
