[R] same random numbers in different sessions
Liviu Andronic
landronimirc at gmail.com
Sun Oct 10 10:30:36 CEST 2010
Hello
On Sun, Oct 10, 2010 at 1:16 AM, jim holtman <jholtman at gmail.com> wrote:
> You need to set the set.seed yourself. There are some simulation
> where I do want the same numbers generated and can use the set.seed to
> set it to a know value. If you want something random each time, then
> use the time of day in the call to set.seed.
>
I try to do this, but I get funny results. I put
try(rm(.Random.seed))
set.seed(Sys.time())
in
/usr/lib/R/etc/Rprofile.site
but I get the following error
Error in rm(.Random.seed) : cannot remove variables from base namespace
[Previously saved workspace restored]
and it is as if the set.seed() call didn't work, since I get the same
random values.
> rnorm(1:10)
[1] -1.3618103 0.4241701 1.0720076 0.2208145 -0.5375314 -0.4846588
[7] 0.7576768 0.6527407 -0.6868786 0.8718527
If I do
> set.seed(Sys.time())
> rnorm(1:10)
[1] -0.6165650 0.6305187 -0.9316815 0.6034638 -0.8593514 -1.0243644
[7] -0.1050344 0.4408562 -0.3466161 0.4058430
manually, within the session, the seed seems to be changed as
requested. Am I doing something wrong?
Liviu
More information about the R-help
mailing list