mercredi 21 juin 2017

Different random number generation between OS in R

I'm getting slightly different random numbers depending on the OS (Mac vs Linux):

set.seed(890458, kind="Mersenne-Twister", normal.kind="Inversion")
print(rlnorm(1504)[1504], digits=22)
sessionInfo()

Linux:

> set.seed(890458, kind="Mersenne-Twister", normal.kind="Inversion")
> print(rlnorm(1504)[1504], digits=22)
[1] 2.732876214731374542311

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0    digest_0.6.12

Mac:

> set.seed(890458, kind="Mersenne-Twister", normal.kind="Inversion")
> print(rlnorm(1504)[1504], digits=22)
[1] 2.732876214731374098221

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.0 digest_0.6.12

Is this expected? Is there anyway to guarantee reproducibility across platforms? It also happens with rnorm rather than rlnorm but with higher numbers.




Aucun commentaire:

Enregistrer un commentaire