Randc behavior using dist operator

Hi All,

consider the following example:

rand bit [1:0] a;

  constraint c1 {
    a dist {

  constraint c2 {
    a dist {

I want to get all the possible values for a (0 1 2 3), but it was not successful with above constraints C1 or C2.

Is it possible to get a randc behavior, where I will get all posssible values when I do randomization 4 times by giving weightage?

Thank You,

The probability of getting all possible values (0,1,2,3 in any order) with just 4 calls to randomize() is 24/256 = 9.375%.

When you randomize a 2-bit variable 4 times, there are 256 outcomes. Only 24 of those outcomes give you randc behavior.

Thank you Dave for the reply, yes it worked.

Also, request you to please suggest the same for;

3 bit rand variable doing randomization for 8 times to get all possible values 0 to 7.
According to my calculation, total outcomes = 4096
80/4096 = 1.953125 %

But some values are getting repeated, I feel my probability/weightage calculation is incorrect. Could you please tell me what is the weightage to be used for all 8 values?

Thank You,

Randomizing a 3-bit number 8 times is 24 random bits: 224 = 16,777,216 possible outcomes. 8! (factorial) = 40,320 of those outcomes do not have numbers that repeat. That means you have 99.97% chance of having a repeating number.

You only get the distributions you specify with the dist constraint as the number of randomizations approach infinity.