runif and sample with reproducibility
When I use set.seed() in R 1.8.1, I get the following: > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(2) > runif(10) [1] 0.1848823 0.7023740 0.5733263 0.1680519 0.9438393 0.9434750 0.1291590 [8] 0.8334488 0.4680185 0.5499837 > set.seed(2) > runif(10) [1] 0.1848823 0.7023740 0.5733263 0.1680519 0.9438393 0.9434750 0.1291590 [8] 0.8334488 0.4680185 0.5499837 What output do you get? Also, keep in mind that the default random number generator changed in (I believe) R 1.7.0 so you may need to use RNGversion() to reproduce results from earlier versions of R. -roger
Eric ESPOSITO wrote:
Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html