Hello everyone!
I have a simple example for random stability in QuestaSim 2024.1.
module sv_rand_stability;
class dummy;
rand int data;
endclass
initial begin
dummy d;
$display("%8h", $urandom());
$display("%8h", $urandom());
d = new();
$display("%8h", $urandom());
$display("%8h", $urandom());
end
endmodule
Output is:
# bedc4ae3
# e6d8f5c9
# 680855e0
# 918c7310
But if i comment out rand:
module sv_rand_stability;
class dummy;
/*rand*/ int data;
endclass
initial begin
dummy d;
$display("%8h", $urandom());
$display("%8h", $urandom());
d = new();
$display("%8h", $urandom());
$display("%8h", $urandom());
end
endmodule
output is not the same:
# bedc4ae3
# e6d8f5c9
# e34f5f73
# 680855e0
According to LRM section 18.14.1:
Each class instance (object) has an independent RNG for all randomization methods
in the class. When an object is created using new, its RNG is seeded with the next random value from the thread that creates the object.
There is no mention that class must contain fields with a rand modifier. Every object must be initialized with random value from thread.
P.S. Xcelium 24.03 has behavior that complies with the standard.
So, my question is, is the behavior of Questa compiles with LRM and why are we seeing it at all? Is this something like optimization?