[R] random number generator

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Jan 20 08:44:22 CET 2000


On Wed, 19 Jan 2000, Clayton Brown wrote:

> This question may not be specific to R, but I'm using R so here goes:
> 
> Since R is slow (as is Splus) I want to split a simulation and run it on
> 2 or 3 systems at once.  The simulations involve generating a large number
> of random values.  How can I set .Random.seed so that the succession of
> random values don't overlap across systems.
> 
> I see that when I invoke R and give command runif(1) a different .Random.seed
> is created each time, but how do I know the stream of random values won't
> overlap when I invoke R on different machines?

What does `overlap' mean?  Even if by chance you get the same part of the
random sequence, they would normally be used for different purposes. If you
use a decent generator (_not_ R's default generator) the seed has so long a
period that the chance of getting the same parts of the sequence are
extremely small.  You could choose starting seeds say 100,000 apart (and
people have published tables of such things), but that ignores a crucial
fact about PRNGs: values M (large) apart are often much less independent
than those close together.

Calculation: my machine can generate about 10^5 RNG per second. Suppose you
do something with them, so you use 10^4 per second (optimistic!)  Then in
24 hours you will use less than 10^9. Super-Duper and Marsaglia-Multicarry
have periods of over 10^18, so the chance of any overlap is less than
10^-9, and the chance of a damaging overlap are much less.

The next version of R will have a function set.seed that is set up in such
a way that calling it with different small integer values generates
quite different `random' (actually pseudo-random, of course) starting
seeds.  Calling that with different values on different machines would
suffice. Until then, just rely on the default startup mechanism. It is not
perfect (and will be improved for 0.99.0) but will suffice if you change
the RNGkind.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list