# [R] random number generator

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 20 12:41:15 CET 2000

```> Date: Thu, 20 Jan 2000 09:58:42 +0000 (GMT)
> From: John Logsdon <j.logsdon at lancaster.ac.uk>
>
>
>
> On Thu, 20 Jan 2000, Prof Brian D Ripley wrote:
>
> > 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.
> > >
>
> [snip]
>
> >
> > 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.
> >
>
> Of course this assumes that you haven't used the same RNG to 'randomise'
> the seeds!  You need to initialise these on different machines manually!

Not so in R. If you do not initialize them they pick up different seeds
from the time.

> But you can change the random number generator by .Random.seed[1] - see
> ?RNG for details so you could well initialise each machine using one
> generator but use another generator for the main sequence.  Perhaps you
> could initialise them from the clock as well - this is a standard
> procedure.  proc.time() returns the time in seconds that have been used
> but this is not very refined - is there a millisecond or finer resolution
> anywhere that picks up a system clock rather than timing a procedure?

Yes, it is the standard procedure, and what is done in R. The clock (in
seconds since 1/1/1970) is used to seed another generator, and that is then
used to seed the chosen generator. So unless you start at the same
second, you get a completely different seed.   (Well, in theory, but the
generators are reliable ones, especially the version for 0.99.0.)

If you only want to do two or three simulations you could just use the
three alternative generators.

--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```