[R] about set.seed

Paul Gilbert pgilbert at bank-banque-canada.ca
Wed Sep 21 15:14:17 CEST 2005


Linda

It is possible to reproduce the same uniform and normal random numbers 
on different architecture, and with all versions of R, with some 
caveats. (In R-0.99 there were some fairly big changes, in R-1.7.0 the 
default generator changed, and in 1.7.1 a bug was fixed in the 
Kindermann-Ramage generator.) I regularly test this on Solaris and a few 
Linux variants myself, and my packages have tests, so it is checked on 
all platforms on which R packages are tested. I have not tested 
bivariate normal or other distributions, so it is possible there is a 
problem, but it seems unlikely to me.

In very long simulations there can be small differences in accumulated 
errors, but you have to try hard to find these. If the difference you 
see is easily noticeable then something else is different. To reproduce 
random numbers you need more information than the seed. You also need to 
be sure you have the same uniform generator (kind) and the same 
transformation to your distribution (e.g. normal.kind). I believe the 
distributed R defaults are the same on all architectures, but you or the 
person that installed R may have set something differently in the 
various things that are run when R starts. Also you do have to be 
careful to set the seed properly.

There are some utilities in the package setRNG which help save and set 
information you need to reproduce random numbers.  The function 
random.number.test() in that package will do some simple tests of 
uniform and normal random numbers. It invisibly returns TRUE if  the 
tests are ok, and stops with a "failed" message otherwise. You might 
look at the various examples in that function, and the documentation for 
the package, if you want to reproduce your random numbers.

Paul Gilbert

nlei at sfu.ca wrote:
> Hi there,
> 
> I have some question about set.seed these days which I may need your help.
> 
> I'm working on some sampling project which need to generate random numbers
> by some distributions(like bivariate normal). I noticed that in different
> computers to run my code,I got very significant different results. Then I
> started to try set.seed command which I wish to see by fixing the same
> random numbers what can happen. But it turned out when I run my codes in two
> computers I still can get different results. I tried different computers.
> Some of them I can get the same results but some not. A special case is I
> run in two computers which have R version 2.0.1 and 2.1.1 separetely. And
> the results are different. 
> 
> Now my question is what's the reason can make the different result happen
> when we run the same codes by setting the same seed?
> 
> This will help me a lot with my project.Thank you very much!
> 
> Linda
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list