1

当您执行以下操作时, 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() 很多次

4

2 回答 2

2

SystemVerilog IEEE Std (1800-2009) 的第 18.13.3 节描述了该srandom功能。第 18 章有一个代码示例,展示了如何将它与$urandom.

于 2011-03-22T23:36:30.107 回答
0

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_value 添加约束以使其落在一个范围之间。

于 2013-01-01T02:38:41.253 回答