2011-03-22 95 views
0

Çrand()srand()功能是非常有用的,当你做这样的事情:srand()函数模拟了SystemVerilog的

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()然后多次

回答

2

SystemVerilog IEEE Std(1800-2009)的18.13.3部分描述了srandom函数。第18章有一个代码示例,显示如何将它与$urandom一起使用。

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