User guide

24-102
SystemVerilog Testbench Constructs
integer success,i;
initial begin
pkt = new(); //instantiate pkt
for (int j = 0; j < 5; j++)
begin
success = pkt.randomize(); /*calling randomize
on object of class packet*/
if(success==0)
$display("Randomization Failed");
else
$display("Randomization Succeeded");
end // end of for loop
end // end of initial block
endprogram
The output of the program is:
payload.size = 12
Randomization Succeeded
payload.size = 17
Randomization Succeeded
payload.size = 8
Randomization Succeeded
payload.size = 40
Randomization Succeeded
payload.size = 10
Randomization Succeeded
Controlling Constraints
The predefined constraint_mode() method can be used either as a
task or a function. The constraint_mode() task controls whether a
constraint is active or inactive. The predefined constraint_mode()
function reports the current ON/OFF value for the specified variable.
All constraints are initially active.