[R] Same initial seed

Duncan Murdoch murdoch at stats.uwo.ca
Mon Jun 29 00:58:52 CEST 2009


diegol wrote:
> Hello,
>
> I have tried a few searches without luck before posting, since this one
> seems a pretty basic question. 
> I am using R 2.7.0 on WinXP, as I have long started using this version for
> my thesis work and am reluctant to update fearing consistency/backward
> compatibility issues could happen.
>
> I noticed that whenever I start an R session (launch the console
> application) and run a script involving random number generation, eg:
>
>   
>> rnorm(10)
>>     
>
> I get the same result. In fact, each time I start a new R session and enter
>
>   
>> .Random.seed
>>     
>
> I get the same exact vector. From ?.Random.seed:
>
> "Initially, there is no seed; a new one is created from the current time
> when one is required. Hence, different sessions will give different
> simulation results, by default." (as stated in R 2.7.0's documentation)
>
> When I try RSiteSearch(".Random.seed") I get this updated result:
>
> "Initially, there is no seed; a new one is created from the current time
> when one is required. Hence, different sessions started at (sufficiently)
> different times will give different simulation results, by default. However,
> the seed might be restored from a previous session if a previously saved
> workspace is restored."
>
> My PC clock is working fine. I think the problem is not related to allotting
> "sufficient" time between sessions either, which leads me to think this has
> to do with a previously saved workspace, which in the case I mention is
> indeed restored.
>
> I would like to generate different random numbers in each session. The two
> choices I seem to have are: 
> i) Not restore the workspace so a new seed is created from the current time
> (I have to look into how to go about this); 
>   

That's the best choice.  Why do you want all the leftovers from the 
previous session?  It's better to start with a clean slate.

> ii) Leave the workspace alone and manually set a new seed via set.seed()
>   

That's a good idea to make your work reproducible.  This is not 
exclusive of i); do both.
> Am I leaving any options out or getting something wrong?
>   

A third choice is to remove .Random.seed, and then the timer will be 
used to regenerate it.   But i) *and* ii) are better ideas.

Duncan Murdoch
> Thank you.
>
> -----
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> Diego Mazzeo
> Actuarial Science Student
> Facultad de Ciencias Económicas
> Universidad de Buenos Aires
> Buenos Aires, Argentina
>




More information about the R-help mailing list