randomize
randomize方法
所属对象:randomize是 SystemVerilog 中类(class)的一个方法。它主要用于对类中的随机变量(rand 和 randc 类型)进行随机化操作。
工作原理:
当调用一个类对象的randomize方法时,它会根据类中定义的约束(constraint)来为随机变量生成合适的值。
std::randomize
std::randomize函数
所属范畴:std::randomize是一个作用域随机化函数。它允许用户在当前作用域(例如一个函数内部)对变量进行随机化,而不需要将这些变量定义为类的成员变量。
工作方式:
可以将需要随机化的变量作为参数传递给std::randomize。例如:
std::randomize(ssc_ppm) with {
ssc_ppm inside {4'b0010, 4'b0100, 4'b0110, 4'b1000, 4'b1010};
};
class thursday_seq extends junk_seq_seq; //which extends uvm_sequence
rand int count;
constraint c1 { count >= 2; count <= 9; }
function new(string name="thursday_seq");
super.new(name);
if (std::randomize(count)) begin
`uvm_info("",$psprintf(" cnt=%0d .....",count),UVM_LOW) end
else $finish;
if (randomize(count)) begin
`uvm_info("",$psprintf(" cnt=%0d .....",count),UVM_LOW) end
else $finish;
if (this.randomize()) begin
`uvm_info("",$psprintf(" cnt=%0d .....",count),UVM_LOW) end
else $finish;
$finish;
endfunction:new
endclass