Constraint Randomization Interview Question

In reply to ben@SystemVerilog.us:

Hi Ben ,

As the constraints are solved in conjunction with each other ,
the constraint solver would implicitly ensure that max value of int1 is 22 .

If int1 were to be chosen as 25 the constraint :: ( int2 == int1 + 9 )

would Never be Successful as int2 can’t be greater than 31 !!

( due to constraint UPPER_BOUND )

Another way is to check this is using in-line constraint ::


if (! ( c1.randomize() with { int1 == 25 ; } ) ) $display(" XXX FAILS !! XXX ");

This ALWAYS Fails due to Conflicting Constraint UPPER_BOUND and DIFF