Cross-OS consistency: yes
If you installed R on two different operating systems without manually changing defaults or the RProfile
, you should get the same results when using set.seed()
.
Consistency over versions of R: not necessarily
It used to be the case that set.seed()
would give the same results across R versions, but that's no longer generally true thanks to a little-announced update in R 3.6.0. So you can get cross version consistency comparing results before R 3.6.0, but if you compare a post-3.6.0 use of set.seed()
to a pre-3.6.0 use of set.seed()
, you will get different results.
You can see that in the examples below:
R 3.2.0
> set.seed(1999)
> sample(LETTERS, 3)
[1] "T" "N" "L"
R 3.5.3
> set.seed(1999)
> sample(LETTERS, 3)
[1] "T" "N" "L"
R 3.6.0
set.seed(1999)
sample(LETTERS, 3)
[1] "D" "Z" "R"
The reason for the inconsistency is that in R 3.6.0, the default kind of under-the-hood random-number generator was changed. Now, in order to get the results from set.seed()
to match, you have to first call the function RNGkind(sample.kind = "Rounding")
.
R 3.6.0
> RNGkind(sample.kind = "Rounding")
Warning message:
In RNGkind(sample.kind = "Rounding") : non-uniform 'Rounding' sampler used
> set.seed(1999)
> sample(Letters, 3)
[1] "T" "N" "L"
set.seed()
passes the seed to it. Hence, it shouldn't depend on OS and R version. So, 1. Yes. 2. Yes. – Suren