IMPORTANT NOTICE: Please be advised that the Verification Academy Forums will be offline for scheduled maintenance on Sunday, April 6th at 2:00 US/Pacific.
There is no conflict with the code shown. Only active constraints during randomise() are considered. The constraint solver is done by the time post_randomize() gets called.
Thanks Dave.
what if there was a pre_randomize() defined as well as below:
class ABC;
rand int A;
constraint c_a{
A == 50;
}
function pre_randomize();
A.rand_mode(0);
endfunction
function post_randomize();
A = 100;
endfunction
endclass
That should not have any bearing on the randomization of A and also the fact that we are overriding the value in post_randomize? i missed that part of the code earlier. I get a solver issue with the above pre_randomize and none without it.
All active constraints must be satisfied. Turning rand mode of A off does not deactivate the constraint. You need to turn off the constraint with a_c.constraint_mode(0), or set A = 50;
@dave_59 i understand that rand_mode and constraint_mode are exclusive but turning off rand_mode here will set it to default which is 0 and that does not satisfy the constraint. is my understanding correct?
I would have used the word independent instead of exclusive. Assuming you have just constructed the class, A would have the default initial value 0 and would not be able to satisfy the active constraint.
Thanks @dave_59 that clears my understanding of how it works.
I guess if I had the constraint declared as ‘soft’, that would get rid of the solver failing too.