File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 5
5
# R's lazy-loading package scheme causes the private seed to be cached in the
6
6
# package itself, making our PRNG completely deterministic. This line resets
7
7
# the private seed during load.
8
- withPrivateSeed(set.seed( NULL ))
8
+ withPrivateSeed(reinitializeSeed( ))
9
9
}
Original file line number Diff line number Diff line change @@ -84,6 +84,15 @@ withPrivateSeed <- function(expr) {
84
84
)
85
85
}
86
86
87
+ # a homemade version of set.seed(NULL) for backward compatibility with R 2.15.x
88
+ reinitializeSeed <- if (getRversion() > = ' 3.0.0' ) {
89
+ function () set.seed(NULL )
90
+ } else function () {
91
+ if (exists(' .Random.seed' , globalenv()))
92
+ rm(list = ' .Random.seed' , pos = globalenv())
93
+ runif(1 ) # generate any random numbers so R can reinitialize the seed
94
+ }
95
+
87
96
# Version of runif that runs with private seed
88
97
p_runif <- function (... ) {
89
98
withPrivateSeed(runif(... ))
You can’t perform that action at this time.
0 commit comments