-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code_5 Single Constraint to genrate_random_value.sv
59 lines (47 loc) · 1.5 KB
/
Code_5 Single Constraint to genrate_random_value.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// write a single Constraint to generate random values for bit[8:0] variable in the below range: 1-34,127,129-156,192-202,257-260.
class sample;
rand bit[8:0]var1;
constraint variable_c{
var1 inside{[1:34],127,[129:156],[192:202],[257:260]};
}
function void print();
if(var1>=1 && var1<=34)
$display("Variable range is[1:34]=",var1);
else if(var1>=129 && var1<=156)
$display("Variable range is[129:156]=",var1);
else if(var1>=192 && var1<=202)
$display("Variable range is[192:202]=",var1);
else if(var1>=257 && var1<=260)
$display("Variable range is[257:260]=",var1);
endfunction
endclass
module top;
sample s;
initial begin
s=new();
repeat(20)begin
s.randomize();
s.print();
end
end
endmodule
//OUTPUT is
/* Variable range is[129:156]=131
Variable range is[129:156]=150
Variable range is[129:156]=150
Variable range is[1:34]= 33
Variable range is[1:34]= 10
Variable range is[1:34]= 13
Variable range is[129:156]=149
Variable range is[1:34]= 19
Variable range is[1:34]= 19
Variable range is[1:34]= 29
Variable range is[129:156]=147
Variable range is[257:260]=257
Variable range is[129:156]=155
Variable range is[1:34]= 28
Variable range is[1:34]= 33
Variable range is[1:34]= 6
Variable range is[129:156]=139
Variable range is[129:156]=132
Variable range is[129:156]=136*/