Static randc declration

Hi,

LRM (2009) states the following statement.

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.

good explanation Mr.Dave.
Now i am able to understand the LRM statement with your simple clear cut example.

Thank you.

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

,

In reply to rohit_kumar:

Can you explain what you mean by “It is violating”? The output looks fine to me.

In reply to dave_59:

the last sequence if you see,
C1: B=4
C2: B=4

its coming,according to the statement, C1:B & C2:B has to pick successive values but here its not happening.

In reply to rohit_kumar:

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.