Please don't mess with the random number generator without good reason!
You will mess me up a whole lot! You can of course change the default
behavior of set.seed without affecting me. Here are my thoughts on
set.seed.
Despite the fact that the Blue Book says set.seed takes an integer
argument, and despite the fact that the Splus version of set.seed does
take an integer argument, I don't think anyone who actually does a lot
of random experiments would actual want to use set.seed like that. The
reason is that you often want to reproduce a random experiment after
you've done it, and of course, often, you don't set the seed before you
do the experiment. To get around this I save the starting .Random.seed
with my simulation experiments. Then I have my own set.seed (in Splus
and in R) which works directly with the .Random.seed, so in Splus it
takes 12 (small) integers as its argument and in R it takes 3 integers.
I also allows a single integer argument for Blue Book compatibility and
in Splus I use their set.seed (which I rename) for this case. As you may
see below, the default behavior in R is rather ad hoc. Below are my
Splus and R versions of set.seed. The R version has a minor workaround
for the problem that the R .Random.seed does not seem to exist until the
random number generator is used the first time. I also prefer returning
the new seed as the value of the function.
Paul Gilbert
______________
in R
set.seed <- function(seed=NULL)
{if (is.null(seed))
{if (!exists(".Random.seed")) zzz <- runif(1) # seed may
not
yet exist
seed <-.Random.seed
}
else
{if (1==length(seed))
global.assign(".Random.seed",round(runif(3,min=seed,max=1e5*seed)))
else global.assign(".Random.seed", seed)
}
seed
}
global.assign <- function(name, value)
{assign(name,value, envir=.GlobalEnv)}
in S
set.seed <- function(seed=NULL)
{if (is.null(seed))
seed <-.Random.seed
else
{if (1==length(seed)) set.seed.Splus(seed)
else global.assign(".Random.seed", seed)
}
seed
}
global.assign <- function(name, value) {assign(name,value, where 1)}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-