User guide
24-73
SystemVerilog Testbench Constructs
Set Membership
You can use the inside operator to specify a set of possible values
that VCS randomly applies to the random variable.
program prog;
class myclass;
rand int int1;
constraint c1 {int1 inside {1, [5:7], [105:107]};}
endclass
myclass mc = new;
initial
repeat (10)
if(mc.randomize()==1)
$display("int1=%0d",mc.int1);
endprogram
Constraint c1 specifies that the possible values for int1 are as follows:
•1
• a range beginning with 5 and ending with 7
• a range beginning with 105 and ending with 107
The $display system task displays the following:
int1=1
int1=7
int1=5
int1=107
int1=106
int1=5
int1=5
int1=6
int1=107
int1=1