Re: picking a new random seed
- From: rbe <bernecky@xxxxxxxxx>
- Date: Tue, 29 Jan 2008 06:15:33 -0800 (PST)
On Jan 26, 8:47 pm, Sam Sirlin <swsir...@xxxxxxxxxxx> wrote:
Charles Brenner wrote:
When doing Monte Carlo simulations, it may be uninteresting to redo
the same ones every time the workspace is loaded. As a crude method to
avoid reusing the same random number sequence, I wrote a loop to run
for one second generating a random number each time. To my surprise
the number of iterations in a second shows very little variation --
85% of 1-second trials ran the same number of iterations hence ended
with the same random seed. Also, that number was quite small. (APL
+DOS: It was 814 but I did also advance a counter in the loop.)
I guess it would be better just to read the system clock. At 100 tics
per second, there are as many tics in a year as the number of valid
values for []RL.
If you really care, you probably want to check out whatever generator
you use with various tests. There are numerous references on the web,
for instance
http://www.math.utah.edu/~pa/Random/Random.htmlhttp://csrc.nist.gov/groups/ST/toolkit/rng/index.html
Sam
The real-time cycle counter on modern X86 processors provide a
timestamp that
should change often (every machine cycle!) enough to keep Charles
happy. Here's a DDJ article that
gives a snippet of C code to read it:
http://www.ddj.com/showArticle.jhtml?documentID=ddj0405b&pgno=2
Here's the definition of RTDSC from: "Intel® 64 and IA-32
Architectures
Optimization Reference Manual":
"The time-stamp counter increments whenever the sleep pin is not
asserted or when
the clock signal on the system bus is active. It is read using the
RDTSC instruction.
The difference in values between two reads (modulo 2**64) gives the
number of
processor clocks between reads."
Now, having said that...
I don't know which RNG you're using, but the one in most early vintage
APL
interpreters (linear congruential) is not the greatest in the world.
You'd be better off adopting
one of the more modern RNG algorithms if cycle size, distribution
characteristics,
etc., are important to your application.
Bob
Bob
.
- References:
- picking a new random seed
- From: Charles Brenner
- Re: picking a new random seed
- From: Sam Sirlin
- picking a new random seed
- Prev by Date: Re: Unix-Z or WinZip Compression
- Next by Date: Re: Unix-Z or WinZip Compression
- Previous by thread: Re: picking a new random seed
- Next by thread: Re: picking a new random seed
- Index(es):
Relevant Pages
|