Skip to content

runif and sample with reproducibility

6 messages · Eric ESPOSITO, Roger D. Peng, Brian Ripley +3 more

#
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
#
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:
#
On Mon, 5 Jan 2004, Eric ESPOSITO wrote:

            
There *was* an answer posted, see the archives here:

https://www.stat.math.ethz.ch/pipermail/r-help/2003-December/042422.html

and none of the rest of us has any idea why this does not work for you
(if indeed it does not).

  
    
#
Hi Eric,

How about:
[1] 57 72 90  3 74 46  9 81 95 78
[1] 57 72 90  3 74 46  9 81 95 78
Cheers,

Anders.
On Mon, 5 Jan 2004, Eric ESPOSITO wrote:

            
#
On Mon, Jan 05, 2004 at 01:07:08PM +0100, Eric ESPOSITO wrote:
help(set.seed)

Hth, Dirk
#
Hallo

I think I have seen an answer to it but did not search for it.

set.seed() with sample() is perfectly reprodicble for me (well, I 
tried it only three times :-)
[1]  8 93 38 14 23 51 86 31 75 34
[1]  8 93 38 14 23 51 86 31 75 34
[1]  8 93 38 14 23 51 86 31 75 34
 
I suspect you called "set seed" only once.

Cheers
Petr
On 5 Jan 2004 at 13:07, Eric ESPOSITO wrote:

            
Petr Pikal
petr.pikal at precheza.cz