It is quite hard to explain. Basically, $random is a pseudo random sequence. Yes, once the seed is known, you can 预先知道产生的随机序列.<br>
<br>
Upon callling, $random(seed) task modifies the seed variable (seed "output" value is different than seed "input" value). To get to the next vaule in the 随机序列, you can either call $random(seed) or just $random(). If you don't provide the seed in your next call, it resue the seed output value from your last call. Verilog-2001 does not support "per-thread" randomization, and sometimes people uses this feature (using the seed "output" value to feed next seed "input") to emulate "per-thread" randomization.<br>
<br>
Here is an example:<br>
<br>
initial begin<br>
seed = 1;<br>
$display("\nseed %0d random sequence", seed);<br>
for (int i=0; i<10; i++) begin<br>
$write("before calling seed=%d, ", seed);<br>
random_val = $random(seed);<br>
$display("after calling seed=%d, random value=%d", seed, random_val);<br>
end<br>
<br>
seed = 2;<br>
$display("\nseed %0d random sequence", seed);<br>
for (int i=0; i<10; i++) begin<br>
$write("before calling seed=%d, ", seed);<br>
random_val = $random(seed);<br>
$display("after calling seed=%d, random value=%d", seed, random_val);<br>
end <br>
<br>
seed = 1;<br>
$display("\nseed %0d random sequence", seed);<br>
for (int i=0; i<10; i++) begin<br>
$write("before calling seed=%d, ", seed);<br>
random_val = $random(seed);<br>
$display("after calling seed=%d, random value=%d", seed, random_val);<br>
end<br>
<br>
$finish;<br>
end<br>
<br>
Here is the output:<br>
# run -all <br>
# <br>
# seed 1 random sequence<br>
# before calling seed= 1, after calling seed= 69070, random value=-2147414528<br>
# before calling seed= 69070, after calling seed= 475628535, random value=-1671855048<br>
# before calling seed= 475628535, after calling seed=-1017563188, random value= 1129920902<br>
# before calling seed=-1017563188, after calling seed= 772999773, random value=-1374483364<br>
# before calling seed= 772999773, after calling seed= -417135238, random value= 1730349006<br>
# before calling seed= -417135238, after calling seed= -473131853, random value= 1674352583<br>
# before calling seed= -473131853, after calling seed= 1662200408, random value= -485282618<br>
# before calling seed= 1662200408, after calling seed= 2044158073, random value= -103324941<br>
# before calling seed= 2044158073, after calling seed= -505977370, random value= 1641506755<br>
# before calling seed= -505977370, after calling seed= 797919023, random value=-1349564321<br>
# <br>
# seed 2 random sequence<br>
# before calling seed= 2, after calling seed= 138139, random value=-2147345408<br>
# before calling seed= 138139, after calling seed= 951188000, random value=-1196295055<br>
# before calling seed= 951188000, after calling seed= 1784212385, random value= -363270956<br>
# before calling seed= 1784212385, after calling seed=-1731404562, random value= 416079665<br>
# before calling seed=-1731404562, after calling seed=-1607270249, random value= 540214080<br>
# before calling seed=-1607270249, after calling seed= -529128468, random value= 1618355648<br>
# before calling seed= -529128468, after calling seed= -497434627, random value= 1650049476<br>
# before calling seed= -497434627, after calling seed=-1868851558, random value= 278632737<br>
# before calling seed=-1868851558, after calling seed= 1238854483, random value= -908628845<br>
# before calling seed= 1238854483, after calling seed= 2101815416, random value= -45667590<br>
# <br>
# seed 1 random sequence<br>
# before calling seed= 1, after calling seed= 69070, random value=-2147414528<br>
# before calling seed= 69070, after calling seed= 475628535, random value=-1671855048<br>
# before calling seed= 475628535, after calling seed=-1017563188, random value= 1129920902<br>
# before calling seed=-1017563188, after calling seed= 772999773, random value=-1374483364<br>
# before calling seed= 772999773, after calling seed= -417135238, random value= 1730349006<br>
# before calling seed= -417135238, after calling seed= -473131853, random value= 1674352583<br>
# before calling seed= -473131853, after calling seed= 1662200408, random value= -485282618<br>
# before calling seed= 1662200408, after calling seed= 2044158073, random value= -103324941<br>
# before calling seed= 2044158073, after calling seed= -505977370, random value= 1641506755<br>
# before calling seed= -505977370, after calling seed= 797919023, random value=-1349564321<br>
# ** Note: $finish : test.sv(211) |