# Assert(std::randomize(variable))

**URL:** <https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, assertstdrandomizevariable\
**Created:** [May 27, 2014, 10:53am UTC](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518 "2014-05-27T10:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rankpat123](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@rankpat123](https://verificationacademy.com/forums/u/rankpat123)\
**Post date:** [May 27, 2014, 10:53am UTC](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/1 "2014-05-27T10:53:47Z")

</div>

Hello,  
Could you please let me know what simulators should do when we use  
assert(std::randomize(variable))  
and assertions are turned off

I am using it but bit confused what should simulators do ?  
will it still randomize variable  
or keep previous value  
or it is going to be 0 (variable is int)

Thanks

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 27, 2014, 8:03pm UTC](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/2 "2014-05-27T20:03:11Z")

</div>

The LRM just says that **$assertoff** _shall stop the checking of all specified assertions_. The LRM does not specifically mention if the evaluation of expression is inseparable from its checking. Apparently, most simulators ignore the entire assertion statement when the assertion is turned off. This has the unfortunate consequence of not calling the randomize method.

We recommend using a simple **if ( randomize() )** statement to avoid this issue as well as having an assert statement in your testbench interferes with the reporting of functional coverage of your design.

---

<div class="post-metadata">

**Author:** ![shalom](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/53a042/32.png) [@shalom](https://verificationacademy.com/forums/u/shalom)\
**Post date:** [May 28, 2014, 8:12am UTC](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/3 "2014-05-28T08:12:12Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/2):_

For performance reasons, it is logical to ignore the assertion entirely when turned off.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/1084_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [June 4, 2014, 6:16pm UTC](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/4 "2014-06-04T18:16:36Z")

</div>

_In reply to [shalom](https://verificationacademy.com/forums/t/assert-std-randomize-variable/29518/3):_

per a recommendation from my Co-author Srinivasan Venkataramanan,

```auto
// assert(req.randomize()); // ** AVOID THIS 
if (!req.randomize()) `uvm_error("USER_DEFINED_FLAG", "This is a randomize error");

```

## //req is a class handle in the above example

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- SystemVerilog Assertions Handbook, 2005 ISBN 0-9705394-7-9
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 0-9705394-2-8
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *
