-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern_0102030405.sv
More file actions
45 lines (27 loc) · 1004 Bytes
/
pattern_0102030405.sv
File metadata and controls
45 lines (27 loc) · 1004 Bytes
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
//Write a constraint to generate the pattern 0102030405
class num_pattern;
rand int num[]; //dynamic array
constraint c1 {num.size() == 10;}
constraint c2 {foreach (num[i])
if (i%2 == 0) //even index
num[i] == 0; //@ index 0, 2, 4, 6, 8
else //odd index
if (i == 1)
num[i]==1; //@ index 1
else
num[i]==num[i-2]+1;} //@ index 3,5,7,9
function void post_randomize();
$display("The generated pattern is : %0p", num);
endfunction: post_randomize
endclass: num_pattern
module pattern;
num_pattern np;
initial begin
np = new();
assert(np.randomize());
end
endmodule: pattern
/*For solving this type of problems where one's asked to generate a certain
pattern consisting of certain numbers consider that pattern as an array of
numbers. At first declare a random dynamic array of numbers.
*/