Care should be taken with this method not to encounter the
birthday problem, described
https://www.johndcook.com/blog/2016/01/29/random-number-generator-seed-mistakes/.
Since the sitmo
threefry
, this currently generates
one random deviate from the uniform distribution to seed the
engine threefry
and then run the code.
rxunif(min = 0, max = 1, n = 1L, ncores = 1L)
min | lower and upper limits of the distribution. Must be finite. |
---|---|
max | lower and upper limits of the distribution. Must be finite. |
n | number of observations. If |
ncores | Number of cores for the simulation
|
uniform random numbers
Therefore, a simple call to the random number generated followed by a second call to random number generated may have identical seeds. As the number of random number generator calls are increased the probability that the birthday problem will increase.
The key to avoid this problem is to either run all simulations in the
RxODE
environment once (therefore one seed or series of seeds
for the whole simulation), pre-generate all random variables
used for the simulation, or seed the RxODE engine with rxSetSeed()
Also care should be made that the computer you will be running on can run the same number of cores as you are running so they can reproduce your results.
# \donttest{
## Use threefry engine
rxunif(min = 0, max = 4, n = 10) # with rxunif you have to explicitly state n
#> [1] 2.134726240 0.007952281 1.279568680 2.254002313 0.841863684 0.325005806
#> [7] 2.110872169 0.565347202 3.019588167 3.310655423
rxunif(min = 0, max = 4, n = 10, ncores = 2) # You can parallelize the simulation using openMP
#> [1] 2.9263972 0.4667526 2.2519018 2.2168082 1.7568379 3.8306717 3.5771028
#> [8] 3.0168567 3.7114864 2.1008062
rxunif()
#> [1] 0.8135653
## This example uses `rxunif` directly in the model
rx <- RxODE({
a <- rxunif(0, 3)
})
#>
et <- et(1, id = 1:2)
s <- rxSolve(rx, et)
# }