Constraint for randomization

Hi,
I have 2 random variables a,b.
But a should appear 10 times frequently as b.

How do I write this constraint?

Thanks & Regards,
Gurumoorthy

In reply to GURUMOORTHY:

Are you crating new object every time when you randomize it or you randomizing same object 10 times ??

In reply to GURUMOORTHY:

If you randomizing same object you can use following code.

class xyz;

rand int a,b;
int i =0 ;

constraint ab_c {if(i <10 ) (b==a);}

function post_randomize()
i = i+1 ;
endfunction

endclass

In reply to GURUMOORTHY:

If you are creating object before each randomization then

class xyz;

rand int a,b;
static int i =0 ;

constraint ab_c {if(i <10 ) (b==a);}

function post_randomize()
i = i+1 ;
endfunction

endclass

In reply to Chandra Bhushan Singh:
creating new object actually.

can you tell way to do that for the one with different object and also for randomizing same object.

[i]In reply to Chandra Bhushan Singh:[/s

Hi,
I am sorry, I couldn’t see the solutions since my page was not refreshed. Thanks very much for your help.

In reply to Chandra Bhushan Singh:

hi,
constraint ab_c {if(i <10 ) (b==a);}

what does this mean?
especially b==a?

In reply to GURUMOORTHY:

This mean a and b is equal for first 10 randomization.

In reply to Chandra Bhushan Singh:

equal in the sense. Values must be different. They should be random values.

In reply to GURUMOORTHY:

a and b is declared as random so it takes random vales but for first times its equal.

In reply to GURUMOORTHY:

Hi GURUMOORTHY,

Could you elaborate more on “a should appear 10 times frequently as b.”?
It is better if you can specify here a sample output (that you are expecting post randomization).

Thanks

In reply to Chandra Bhushan Singh:

a and b should be independent of each other.
But random variable generation constraint should be frequency of randomization of variable b must be 10 times slower when compared to that of a.

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

In reply to S.P.Rajkumar.V:

This is more suitable I guess.