Randc Solved before rand

LRM Section 18.4.2 states :: " A set
of constraints that includes both rand and randc variables shall be solved so that the randc variables are
solved first, and this can sometimes cause randomize() to fail. "


 
class A;

rand bit [1:0] br;

randc bit [1:0] brc;


constraint CC { brc > br ; }

endclass


I thought since randc Cycles through all its Values I might get randomize() Failure but that wasn’t the Case . In this case randc Doesn’t cycle through its set of values to satisfy the constraint

Just wanted an example along the Lines of 18.4.2 of LRM which would cause randomize() to Fail ?

Warm Regards ,
AGIS

In reply to Etrx91:

The terms “solved first” or “solve before” can be misleading. A solution space representing all possible solutions that satisfy the constraints gets created first. Then values are picked for each random variable in the required order.

In your example, brc == 0 is not part of the solution space because constraint CC can never be satisfied regardless of whether brc is declared rand or randc. br ==0 is always a valid value regardless of which valid value is picked for brc.

In the case when both br and brc are declared randc, then you can have a failure with the following scenario

br brc brc>br
0  1      1
1  3      1
2  2      0 // fails because 2 is the only available value for brc

In reply to dave_59:

Hi Dave,

Yes I tried making both variables as randc and had the same constraint

I did get a Failure ( randomize() Called 100 times from repeat )
[ Only 1 out of 3 simulators I tried this on gave a Failure ]

In this Case Solution Space for br Includes all 4 Values and for brc it Excludes 0 .
Constraints are Solved Bi-directionally
so brc might get its value before br and vice-versa also holds true

In the 2 - 2 case ,

( 1 ) If br is chosen as 2 first , Shouldn’t the solver chose brc as 3 ?
( 2 ) if brc is chosen as 2 first , Shouldn’t the solver chose brc Smaller then 2 ?

Do the constraints come into picture for Only deciding the Solution space or is it even also for Deciding the Values within the solution space ?

One Case where I see the failure happening is when br is chosen ( before brc ) as 3 .

Regards ,
AGIS

In reply to Etrx91:
The table I show above is an ordered set of solved values, not the solution space.
Here is another way to think of this. Below is the entire solution space that meets the constraint brc > br:

br brc 
0  1 
0  2 
0  3
1  2
1  3
2  3

The range of available values for br is 0,1,2, and the range of available values for brc is 1,2,3. The constraint solver builds this solution space (rather, a symbolic model of it) before choosing any values. When there are no other directives that introduce a random variable ordering, the solver just randomly picks one of the six solutions. But when both variables are declared with randc, it possible to come up with the solution sets {0, 1}, {1,2}, and {2,3} with any cyclic ordering and never fail, but there in nothing in the LRM that dictates this kind of ordering between variables, only cyclic ordering within each variable.