|
|
|
|
|
|
|
|
|
|
|
|
rand_mode()
|
|
|
Systemverilog provides the predefined rand_mode() method to control whether a random variable is active or inactive. When a random variable is inactive, it is treated the same as if it had not been declared rand or randc. All random variables are initially active. |
|
|
|
|
|
Syntax |
|
|
|
|
|
task object[.random_variable]::rand_mode( bit on_off );
or
function int object.random_variable::rand_mode();
|
|
|
|
|
|
Where |
|
|
|
|
|
- object:The object is any expression that yields the object handle in which the random variable is defined.
- random_variable:The random_variable is the name of the random variable to which the operation is applied. If it is not specified (only allowed when called as a task), the action is applied to all random variables within the specified object.
- 1 (ON): Sets the specified variables to active so that they are randomized on subsequent calls to the randomize() method.
- 0 OFF: Sets the specified variables to inactive so that they are not randomized on subsequent calls to the randomize() method.
|
|
|
|
|
|
When called as a function, rand_mode() returns the current active state of the specified random variable. It returns 1 if the variable is active (ON) and 0 if the variable is inactive (OFF). |
|
|
|
|
|
|
|
|
|
|
|
Example : rand_mode()
|
|
|
|
|
|
1 program rand_mode_ex;
2 class frame_t;
3 rand bit [7:0] src_addr;
4 rand bit [7:0] dst_addr;
5 task print();
6 begin
7 $write("Source address %2x\n",src_addr);
8 $write("Destination address %2x\n",dst_addr);
9 end
10 endtask
11 endclass
12
13 initial begin
14 frame_t frame = new();
15 integer j = 0;
16 $write("-------------------------------\n");
17 $write("Without Randomize Value\n");
18 frame.print();
19 $write("-------------------------------\n");
20 $write("With Randomize Value\n");
21 j = frame.randomize();
22 frame.print();
23 $write("-------------------------------\n");
24 $write("With Randomize OFF and Randomize\n");
25 frame.rand_mode(0);
26 j = frame.randomize();
27 frame.print();
28 $write("-------------------------------\n");
29 $write("With Randomize ON and Randomize\n");
30 frame.rand_mode(1);
31 j = frame.randomize();
32 frame.print();
33 $write("-------------------------------\n");
34 $write("With Randomize OFF on dest addr and Randomize\n");
35 frame.dst_addr.rand_mode(0);
36 j = frame.randomize();
37 frame.print();
38 $write("-------------------------------\n");
39 end
40 endprogram
You could download file rand_mode_ex.sv here
|
|
|
|
|
|
Simulation Output : rand_mode()
|
|
|
|
|
|
-------------------------------
Without Randomize Value
Source address 00
Destination address 00
-------------------------------
With Randomize Value
Source address 36
Destination address 3c
-------------------------------
With Randomize OFF and Randomize
Source address 36
Destination address 3c
-------------------------------
With Randomize ON and Randomize
Source address 7d
Destination address e2
-------------------------------
With Randomize OFF on dest addr and Randomize
Source address 0b
Destination address e2
-------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|