[R] Why R simulation gives same random results?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 21 08:07:51 CET 2013

On 20/02/2013 23:13, Greg Snow wrote:
> To know for sure we need to know how you are running these different R
> sessions, but here are some possibilities:
> The help page for "set.seed" says that if no seed exists then the seed is
> set based on the current time (and since 2.14.0 the process ID).  So one
> possibility is that 2 of the sessions are started close enough together
> that they get the same seed.  Or the difference in time and process ID
> cancel each other out.

That is exceedingly unlikely.  We are not told the platform, but AFAIK 
on all common R platforms and current versions of R:

- the time is measured to at least msec accuracy.
- times which might cancel out pid differences are many hours apart.

A while ago it was possible on some platforms to get the same seed by 
starting two R processes on the same clock tick (within 1/60 or 1/100 s 
of each other).  But now you are talking about generating a pretty 
random unsigned integer with 32 bits to set the seed, so the probability 
of coincidence is very small.

> Another possibility (also mentioned in the help page) is that if the seed
> was saved in a previous session then it will be restored in the new
> session, if all the sessions are reading in the same stored session (or
> just the 2 that are the same) then they would start from the same seed.

Much more likely.

> On Tue, Feb 19, 2013 at 6:31 PM, C W <tmrsg11 at gmail.com> wrote:
>> Hi, list
>> I am doing 100,000 iterations of Bayesian simulations.

>> What I did is I split it into 4 different R sessions, each one runs 25,000
>> iteration.  But two of the sessions gave the simulation result.

This falls within the class of parallel simulations.  You would do 
better to set carefully selected seeds: see the vignette for package 

>> I did not use any set.seed().  What is going on here?
>> Thanks,
>> Mike

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list