If a random variable is declared as static, the randc state of the variable shall also be static. Thus randomize chooses the next cyclic value (from a single sequence) when the variable is randomized through any instance of the base class.
Can anybody please explain what exactly this means & usage?
Its probably simpler than what you can put into words. Suppose you had
class C;
randc static int A;
randc int B;
endclass
And then you constructed a few objects of C named c1,c2, etc. Then on each call to c1.randomize(), c2.randomize(), B will go through its cycle of values independently of the other objects since the is a B variable for each object. But since there is only one variable A (C::A), there can only be one cycle of values for A, so each call to c1.randomize(), c2.randomize will go to the next value of A regardless of which object was randomized.
Hi Dave,
But its violating, see the output what i got , please can you explain why it is going wrong
code is as below executed
module top();
class c;
randc static bit[2:0] A;
randc bit[2:0] B;
function void display(string name);
$display("from:%s::A=%d\tB=%d",name,A,B);
endfunction
endclass
c C1= new();
c C2= new();
initial begin
repeat(8) begin
assert(C1.randomize());
C1.display("C1");
assert(C2.randomize());
C2.display("---C2");
end
end
endmodule
But you did not declare B static. So C1.B and C2.B are independent variables - all that is required is that that randomly cycle once through 8 randomizations. Whereas A has cycled twice.