Constraint for randomization

In reply to GURUMOORTHY:

We can use rand_mode() function to switch off the randomization of a particular random variable inside the class before actually randomizing it.

Hope the following code helps to meet your requirement.

class xyz;
  rand int a,b;
endclass

xyz xyz_h = new();
int i = 1;
while(i)
begin
  if(i%10 != 0) begin
    xyz_h.a.rand_mode(0); // switch off the randomization on variable 'a'.
    xyz_h.randomize(); // Only 'b' gets randomized.
    xyz_h.a.rand_mode(1); // switch on the randomization on variable 'a'.
  end else begin
    // Randomizing 'a' only after ten times
    xyz_h.randomize();  // both a, b gets randomized
  end
  i++;
end