jeudi 19 janvier 2017

Random number generators in R such as rnorm giving identical output on repeated runs

I have a script that loads an RData file. This RData file was generated by a different script using the save.image function. When I run the script that loads the RData file, rnorm gives me identical output on every run.

Here is a simple example.

Script to generate RData file,

rm(list = ls())
save.image('test.RData')

Script that loads RData and calls rnorm,

rm(list = ls())
load('test.RData')
input = rnorm(10)
print(input)

I have found one way round this is to use save rather than save.image in the first script. However this is not very convenient because I do not always know in advance which objects from my environment I want to keep. But I would definitely like rnorm to use a different seed each time I run the second script.




Aucun commentaire:

Enregistrer un commentaire