当你这样做时,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),但问题是它应该扫描一次,然后使用rand()多次
发布于 2011-03-23 07:36:30
SystemVerilog IEEE标准(1800-2009)的18.13.3节介绍了srandom函数。第18章有一个代码示例,展示了如何在$urandom中使用它。
发布于 2013-01-01 10:38:41
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添加约束,使其介于某个范围之间,例如。
https://stackoverflow.com/questions/5395513
复制相似问题