I have a question regarding randomization, when an object is created as a shallow copy of another object. In the following code, b2 is created as a shallow copy of b1 and when repeatedly randomized, it produces same values, but instead if b2 is just new’d instead of shallow copy, different values are produced when randomized.
class A;
rand bit [7:0] i;
endclass
program main;
initial
begin
static int i = 0;
A b1;
A b2;
b1 = new();
$display( b1.i );
//b1.a = new();
b1.randomize();
$display( b1.i );
//$display( b2.a.i );
repeat(5)
begin
b2 = new b1;
$display("\nBefore Randomization");
$display( b1.i );
$display( b2.i );
$display("\nAfter Randomization");
b2.randomize();
$display( b1.i );
$display( b2.i );
i++;
end
end
endprogram
Sample output :
0
102
Before Randomization
102
102
After Randomization
102
19
Before Randomization
102
102
After Randomization
102
19
Before Randomization
102
102
After Randomization
102
19
Before Randomization
102
102
After Randomization
102
19
Before Randomization
102
102
After Randomization
102
19
I am looking for an explanation for this kind of randomization behavior.
P.S. : Simulator : Questasim 10.3a_1