[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gEDA: $random function
> James Bird wrote:
> > But using icarus, how do you set the seed variable to the system
> > clock, or some other changing variable? Are there better ways of
> > getting a non-deterministic set of random values on successive
> > simulations?
On Tue, Sep 28, 2004 at 08:39:41PM +1000, John Sheahan wrote:
> [chop] run a tiny perl script that [makes] a one-line file
> which is then `include 'ed
That sets the seed at compile time. I know Icarus is pretty
quick on the compile, but if you want to set things at run
time, try using "plusargs" (and yes this too is standard, and
thus portable to other Verilog compiler/simulators, although
good luck figuring out how to set plusargs from a GUI).
[ldoolitt@recycle verilog]$ cat randseed.v
module main;
integer i, randseed, seed, out;
initial begin
if (!$value$plusargs("randseed=%d", randseed)) randseed=42;
seed = randseed;
for (i=0; i<10; i=i+1) begin
out = $random(seed);
$display(out);
end
end
endmodule
[ldoolitt@recycle verilog]$ iverilog -Wall randseed.v
[ldoolitt@recycle verilog]$ ./a.out
-2144582656
646214477
38602500
-975846261
179453717
-621508939
1163993994
-1622930370
165168915
570580292
[ldoolitt@recycle verilog]$ ./a.out +randseed=100
-2140576256
-1836108251
-667171664
-202409241
-128900368
425654578
459213622
-944222065
-1713799117
-1112840069
[ldoolitt@recycle verilog]$ ./a.out +randseed=42
-2144582656
646214477
38602500
-975846261
179453717
-621508939
1163993994
-1622930370
165168915
570580292
[ldoolitt@recycle verilog]$ SEED=`dd if=/dev/urandom bs=4 count=1 2>/dev/null | hexdump -e '"%d"'`
[ldoolitt@recycle verilog]$ echo $SEED
1381491640
[ldoolitt@recycle verilog]$ ./a.out +randseed=$SEED
-894847851
-1706338252
-1208244625
-1075436417
2115322364
1231061906
709653844
860903270
-2135560703
1016336249
[ldoolitt@recycle verilog]$
- Larry