[S] identical numbers from rnorm()

Jacob A. Wegelin (wegelin@stat.washington.edu)
Wed, 18 Mar 1998 11:37:16 -0800 (PST)


Just now I made the following little discovery. If you

(1) call rnorm() within a function, say, junkfn()

(2) halt junkfn() with control C

(3) call junkfn() again right away

then the "random" number returned by rnorm() within junkfn() is identical
to what was returned at the previous call to junkfn(). Evidently, halting
a function with control C keeps .Random.seed from being updated.

Is this common knowledge?

Below are the details.

"junkfn"<-
function()
{
x <- rnorm(1)
cat(x, "\n")
readline()
}

> junkfn()
0.327491583339151

Dumped
> junkfn()
0.327491583339151

Dumped
> junkfn()
0.327491583339151

Dumped

> # On the other hand, if you allow junkfn() to finish:
> junkfn()
0.327491583339151

[1] ""
> junkfn()
1.79266626300532

[1] ""

I wrote a fancy simulation and wasted several minutes trying to figure out
why it was failing to produce *random* numbers, before discovering this
fact. To check my fancy simulation function, I had been running just the
first few iterations and then halting it with control C.

I submit this mini-discovery in case it's news to anyone else.

Jacob A. Wegelin
Department of Statistics
University of Washington
Box 354322
Seattle WA 98195

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news