User guide

24-115
SystemVerilog Testbench Constructs
The output of this program is:
Setting the seed as 2 through srandom
a = 8, b = 3
a = 14, b = 3
Changing the seed as 1 through srandom
a = 12, b = 13
a = 15, b = 9
Setting the seed once again to 2 through srandom
a = 8, b = 3
a = 14, b = 3
Seeding for Randomization
The srandom() method initializes the current Random Number
Generator (RNG) of objects or threads using the value of the seed.
The following example involves using srandom() to initialize the RNG
for an object using a real variable as the seed.
program test;
class A;
rand logic [7:0] x;
endclass
real r = 1;
A a;
int d1,d2,d3,d4;
initial begin
a = new;
a.srandom(r);//the r is the seed for RNG of a
d1 = a.randomize();
if(d1 == 1) //if randomize() is successful
d2 = a.x; //assign value of the variable x in a to d2
a.srandom(r+1);
d1 = a.randomize();
if(d1 == 1)