Random number generation in Windows - how to use wall clock?

F

FGreen

Guest
I'm trying to generate random numbers in my test bench in the
following manner.

for (i = 0; i < 10; i=i+1 ) begin
rand = $random($time);

...

end

The good thing is, I get a different 'rand' for each loop count, but
when I run the test the next time, I get the same set of 10 random
numbers. $display of $time shows that it's not the wall clock as in,
but the simulation clock (duh...).

How do I get the wall clock in Windows environment for this?

Or, is there a better way to get random numbers that'll differ from
one test run to next, as well as one loop count to another?

Of course, I'll save/print the seed value so I can reproduce the
problem.

Thank you.
 
FGreen wrote:
I'm trying to generate random numbers in my test bench in the
following manner.

for (i = 0; i < 10; i=i+1 ) begin
rand = $random($time);

...

end

The good thing is, I get a different 'rand' for each loop count, but
when I run the test the next time, I get the same set of 10 random
numbers. $display of $time shows that it's not the wall clock as in,
but the simulation clock (duh...).

How do I get the wall clock in Windows environment for this?

Or, is there a better way to get random numbers that'll differ from
one test run to next, as well as one loop count to another?
Use a $plusargs value to initialize your seed register, then use
whatever external means to wish to choose a seed.


--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
 
Stephen Williams <spamtrap@icarus.com> wrote in message news:<34807$417ea31e$40695902$13900@msgid.meganewsservers.com>...
FGreen wrote:
I'm trying to generate random numbers in my test bench in the
following manner.

for (i = 0; i < 10; i=i+1 ) begin
rand = $random($time);

...

end

The good thing is, I get a different 'rand' for each loop count, but
when I run the test the next time, I get the same set of 10 random
numbers. $display of $time shows that it's not the wall clock as in,
but the simulation clock (duh...).

How do I get the wall clock in Windows environment for this?

Or, is there a better way to get random numbers that'll differ from
one test run to next, as well as one loop count to another?

Use a $plusargs value to initialize your seed register, then use
whatever external means to wish to choose a seed.

Hi, thanks for the response.

My question actually is how to choose a seed externally.
I'm in running modelsim from the DOS prompt, and doing
%vsim +SEED='date' ... doesn't work.

integer rand_seed;

if (!($value$plusargs("SEED=%d", rand_seed))) begin
$display ("Setting rand_seed to default");
rand_seed = 0;
end
else begin
$display ("Using rand_seed = %d", rand_seed);
end

Returns Using rand_seed = 0

What am I doing wrong?
 

Welcome to EDABoard.com

Sponsor

Back
Top