[R] Random number generation

From: Dennis Fisher <fisher_at_plessthan.com>
Date: Sat, 10 May 2008 10:55:47 -0700


I have encountered behavior of random number generation that eludes me.

I generate a random integer in a particular range using the following code:

        sample(1000:9999, size=1)

This code exists within a script that starts with the command:


Each time that I run the script, it yields the same random number: 6420.

I thought that the problem might result from deleting the random seed. However, list=ls() does not include .RandomSeed.

To my surprise, I can't replicate the problem with a 2-line script:

	sample(1000:9999, size=1)

Also, the same problem occurs if I use runif instead of sample.



Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220

        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 10 May 2008 - 17:59:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 11 May 2008 - 09:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive