Skip to content
Prev 42439 / 398506 Next

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: