Skip to content

set.seed

2 messages · Jim_Garrett@bd.com, Brian Ripley

#
I'm running into problems with set.seed--maybe I'm misunderstanding
something.

I'm running R 1.5.1 on Windows 2000.

I'm basically trying to capture the random seed so that I can reproduce a
simulation if it's necessary later.  Using set.seed, I can certainly get
reproducible results, but not the results I get on the first pass.  Here's
an example:

# Generate a random number to initialize
[1] 0.965875
[1] "Marsaglia-Multicarry" "Kinderman-Ramage"
[1] 0.18734034 0.02723140 0.46396251 0.10602243 0.64362777
[1] 0.006153224 0.553233950 0.091852441 0.643058504 0.009685173
[1] 0.006153224 0.553233950 0.091852441 0.643058504 0.009685173

So you can see that I can reproduce the latter sequence, but not the first
sequence.  As a workaround, I guess I can call set.seed prior to generating
the first sequence.  But it puzzles me why capturing the random seed
appears not to be sufficient.  Am I overlooking something?

Thanks for any guidance.

Jim Garrett
Becton Dickinson Diagnostic Systems
Baltimore, Maryland, USA


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
You either need to

1) set set.seed before the first run, then set it  again to the first
value.

or

2) save .Random.seed and reset it by

.Random.seed <- temp.seed

Beware that the second approach is not sufficient with the Box-Muller
method.

Your problem is that you have mixed the two approaches.

Hope this helps.
On Mon, 12 Aug 2002 Jim_Garrett at bd.com wrote: