User guide
24-100
SystemVerilog Testbench Constructs
Randomize Methods
randomize()
Variables in an object are randomized using the randomize() class
method. Every class has a built-in randomize() method.
randomize()
Generates random values for active random variables, subject to
active constraints, in a specified instance of a class. This method
returns a 1 if VCS generates these random values, otherwise it
returns 0. Examples of the use of this method appear frequently
in previous code examples.
pre_randomize() and post_randomize()
Every class contains built-in pre_randomize() and post_randomize()
tasks, that are automatically called by randomize() before and after
it computes new random values.
You may override the pre_randomize() method in any class to perform
initialization and set pre-conditions before the object is randomized.
Also, you may override the post_randomize() method in any class to
perform cleanup, print diagnostics, and check post-conditions after
the object is randomized.
The following example involves a case where the pre_randomize()
method is used to instantiate and initialize the rand dynamic array,
payload[], before randomize() is called. The post_randomize()
method is used to display the size of the payload[] after randomize()
is called.
program test;
class size;
rand bit [7:0] s; //random variable s