class base;
rand bit [1:0] typ;
rand bit [3:0] len;
constraint c_typ_len {
typ == 1 -> len > 10;
}
endclass
My intention here is if typ equals 1, then len must be greater than 10.
When randomize() is called upon the object of the above class, what is the order in which typ and len are randomized? Do they both get randomized simultaneously or does typ get randomized first and then len is randomized?
Thanks, Dave. Is my understanding for my above constraint right.
The probability to have typ=1 and len>10 is 5/53. I get this by listing all the valid typ-len values when randomized. So we have -
typ=0; len=0-15 (total of 16 valid pairs)
typ=1; len=11-15 (total of 5 valid pairs)
typ=2; len=0-15 (total of 16 valid pairs)
typ=3; len=0-15 (total of 16 valid pairs)
If I included a ‘solve typ before len’ constraint in my class, the probability to have typ=1 and len>10 is 1/4. Is this right?
The first part without solve/before is correct. Note that the probability of
len>10 is 20/53
The second part with solve/before is not correct. There are still 53 solutions. The probability to have typ=1 and len>10 is now 1/4, or 13.25/53.
The probability of
len>10 is now (13.25 + 3*13.25 * 5/16)/53, or 25.67/53
Trying to figure out how you arrived at the probability no. for the 2nd scenario.
You made a good point that we still have 53 solutions. solve-before simply changes the distribution but not the total available set of soultions, am I right?