I ran the sample()
command in combination with the set.seed()
command to obtain always the same sample and everything worked fine. However, applying the same commands on a different laptop gave back a different sample. Does anyone have any idea what has happened?
I tried also the combination set.seed()
and rnorm()
, surprisingly I got then exactly the same random numbers on both laptops.
set.seed(123)
sample(LETTERS,6)
set.seed(123)
rnorm(6,1,1)
I expected that on both laptops the result "H" "T" "J" "U" "W" "A" is displayed. However, one laptop displayed the result "O" "S" "N" "C" "J" "R".
set.seed(123)
rnorm(6,1,1)
produced
0.4395244 0.7698225 2.5587083 1.0705084 1.1292877 2.7150650
on both laptops.
This is not due to cross-hardware reproducibility issues, but a difference introduced in R 3.6.0 -- you must have one machine on R 3.6.0 and the other on an earlier version. From help("set.seed")
(from R 3.6.0):
Usage
...
set.seed(seed, kind = NULL, normal.kind = NULL, sample.kind = NULL)
...Details
sample.kind can be "Rounding" or "Rejection", or partial matches to these. The former was the default in versions prior to 3.6.0: it made sample noticeably non-uniform on large populations, and should only be used for reproduction of old results. See PR#17494 for a discussion.
Observe the following to see the difference within machine (i.e., this shows it is not a cross-hardware issue, because I'm doing this on only one machine):
set.seed(123, sample.kind = "Rejection") # Default in R 3.6.0
sample(LETTERS, 6)
# [1] "O" "S" "N" "C" "J" "R"
set.seed(123, sample.kind = "Rounding") # Default in R < 3.6.0
sample(LETTERS, 6)
# [Warning omitted]
# [1] "H" "T" "J" "U" "W" "A"