User guide

24-84
SystemVerilog Testbench Constructs
initial
begin
D d = new();
d.y = 1;
d.randomize();
d.y = 0;
d.randomize();
end
endprogram
In the example, the default constraint in block c1 is overriden by the
non-default constraint in block d1. The first call to randomize will pick
a value between 6 and 15 for x, since the non-default constraint is
applicable, given that the guard evaluates to TRUE. The default
constraint is ignored. The guard for the non-default constraint
evaluates to FALSE in the second call, and a value of between 3 and
5 will be picked for x in the next call to randomize. In this randomize()
call, the default constraint is applied.
program test;
class A;
rand reg[3:0] x;
rand reg[3:0] y;
default constraint T{
x == 10 ; y == 10;
}
constraint E {
y == 0;
}
function void post_randomize();
$display("x = %0d y = %0d\n", x, y);
endfunction
endclass
initial
begin
integer ret;
A a = new;
ret = a.randomize();
end
endprogram