[R] Random number generation

Stephan Kolassa Stephan.Kolassa at gmx.de
Sun May 11 09:31:42 CEST 2008


Dennis,

I assume that there is a set.seed() somewhere in your script, possibly 
in something you source()d (hopefully not in anything library()d).

Have you tried successively removing/commenting parts of the script 
before the sample() command until the problem goes away? That way you 
should be able to pinpoint the offending script command.

Good luck,
Stephan


Dennis Fisher schrieb:
> Colleagues,
> 
> 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:
> 	remove(list=ls())
> 
> 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:
> 	remove(list-ls())
> 	sample(1000:9999, size=1)
> 
> Also, the same problem occurs if I use runif instead of sample.
> 
> Thoughts?
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
> 
> 
> 	[[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.
> 
>



More information about the R-help mailing list