Random SystemVerilog的srand()模拟

Random SystemVerilog的srand()模拟,random,verilog,system-verilog,Random,Verilog,System Verilog,Crand()和srand()函数在执行类似操作时非常有用: srand(SEED); for() { //doing something with one thing using rand() } srand(SEED); for() { //doing something with other thing using rand() } 我可以在SystemVerilog中使用类似的东西吗?是的,我知道关于$urandom(SEED),但问题是它应该SRAND一次,rand(

C
rand()
srand()
函数在执行类似操作时非常有用:

srand(SEED);
for()
{
    //doing something with one thing using rand()
}
srand(SEED);
for()
{
    //doing something with other thing using rand()
}

我可以在SystemVerilog中使用类似的东西吗?是的,我知道关于
$urandom(SEED)
,但问题是它应该SRAND一次,rand()然后多次

SystemVerilog IEEE Std(1800-2009)第18.13.3节描述了
srandom
函数。第18章有一个代码示例,展示了如何将它与
$Uradom

一起使用,SystemVerilog中的许多随机化通常在类内完成,其中SV具有强大的随机化基础设施。您通常会这样做:

class Foo;
  rand int r_value;
  function void reseed(int seed);
    srandom(seed);
  endfunction
  function void do_something();  
    randomize();
    $display("something: %0d", value);
  endfunction
  function void do_something_else(); 
    randomize();
    $display("something: %0d", value);
  endfunction
endclass

....

Foo foo = new();
foo.reseed(seed);
foo.do_something();
foo.reseed(seed);
foo.do_something_else();
其优点是SV对每个对象都有一个单独的随机数生成器,因此在更改一个对象的种子时不会更改环境的其余部分。当然,您还可以向r_值添加约束,使其介于某个范围之间,例如