User guide

24-114
SystemVerilog Testbench Constructs
Providing the same seed ensures that the same set of random values
are generated by the random number generator.
The following program demonstrates that the same random numbers
are generated for the same seed.
program test;
logic [3:0] a, b;
initial begin
$display("Setting the seed as 2 through srandom");
$srandom(2);
repeat (2)
begin
a = $urandom();
b = $urandom();
$display("a = %0d, b = %0d", a, b);
end // end of repeat block
$display("Changing the seed as 1 through srandom");
$srandom(1);
repeat (2)
begin
a = $urandom();
b = $urandom();
$display("a = %0d, b = %0d", a, b);
end // end of repeat block
$display("Setting the seed once again to 2 through
srandom");
$srandom(2);
repeat (2)
begin
a = $urandom();
b = $urandom();
$display("a = %0d, b = %0d", a, b);
end // end of repeat block
end // end of initial block
endprogram