Enable/Disable specific constraints:
In below example we can understand how we can enable or disable a specific constraint whenever we need to do.
class rmode;
rand int a;
rand int b;
constraint ct_a { a == 50;}
constraint ct_b { b == 100;}
endclass
program main;
rmode rnd = new();
initial begin
void'(rnd.randomize());
$display(" 1 : a : %0d, b : %0d ",rnd.a, rnd.b);
rnd.ct_a.constraint_mode(0); //disable constraint ct_a
void'(rnd.randomize());
$display(" 2 : a : %0d, b : %0d ",rnd.a, rnd.b);
rnd.ct_a.constraint_mode(1); //enable constraint ct_a
void'(rnd.randomize());
$display(" 3 : a : %0d, b : %0d ",rnd.a, rnd.b);
end
endprogram