The randomize() method can be used to temporarily
control the set of random and state variables within a class instance or
object.
When randomize is called with arguments, those arguments
designate the complete set of random variables within that object; all other
variables in the object are considered state variables.
The randomize method accepts the special argument
null to indicate no random variables for the duration of the call. In other
words, all class members behave as state variables.
Consider following Example:
----------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class rand_mo; | |
rand integer Var1; | |
integer Var2; | |
endclass | |
program rand_mo_p_38; | |
rand_mo obj = new(); | |
initial begin | |
// Random variable: Var1, State Variable: Var2 | |
void'(obj.randomize()); | |
$display(" 1 : Var1 : %0d, Var2 : %0d",obj.Var1, obj.Var2); | |
// Random variable: Var2, State Variable: Var1 | |
void'(obj.randomize(Var2)); | |
$display(" 2 : Var1 : %0d, Var2 : %0d",obj.Var1, obj.Var2); | |
// Random variable: Var1, Var2 | |
void'(obj.randomize(Var1, Var2)); | |
$display(" 3 : Var1 : %0d, Var2 : %0d",obj.Var1, obj.Var2); | |
// State variable: Var1, Var2 | |
void'(obj.randomize(null)); | |
$display(" 4 : Var1 : %0d, Var2 : %0d",obj.Var1, obj.Var2); | |
end | |
endprogram | |
// Output: | |
// 1 : Var1 : -902462825, Var2 : x | |
// 2 : Var1 : -902462825, Var2 : -1241023056 | |
// 3 : Var1 : 69704603, Var2 : -1877783293 | |
// 4 : Var1 : 69704603, Var2 : -1877783293 |
----------------------------------------------------
No comments:
Post a Comment