jeudi 23 mars 2017

How to automatically set the random seed on current time?

Everytime one opens a R console, the random seed is set to the same value. On my computer (it might alike the same on your machine), if I run rnorm(1), I always get 0.1777571 at the first call.

I tried to automatically set the random seed using the computer current time by adding something like

set.seed(
   as.integer(
      as.numeric(
         gsub("[^0-9]","",paste(format(Sys.time(), "%Y %X %x")))
      )%%.Machine$integer.max
   )
)

in the file .Rprofile but it does not change anything. The first call to rnorm(1) always return 0.1777571.

How can I automatically set the random seed to the computer current time?




Aucun commentaire:

Enregistrer un commentaire