User guide

24-110
SystemVerilog Testbench Constructs
The following example illustrates the usage of in-line constraint
checker.
program test;
class myclass;
rand int a, b; // random variable a,b
constraint cc { a + b == 4;}
function new(); // constructor initiliazing values of a
// and b
a = 2;
b = 2;
endfunction
endclass
myclass mc = new;
int i;
initial begin
$display("Calling Randomize method with null args :-");
i = mc.randomize(null); // values of a and b should be
// preserved
$display("a = %0d, b = %0d, return from method = %0d",
mc.a, mc.b, i); // should display a and b as 2
end
endprogram
The output of this program is:
Calling Randomize method with null args :-
a = 2, b = 2, return from method = 1