Unless future.seed = FALSE
, this function guarantees to generate
the exact same sequence of random numbers given the same initial
seed / RNG state - this regardless of type of futures and scheduling
("chunking") strategy.
RNG reproducibility is achieved by pregenerating the random seeds for all
iterations (over x
) by using L'Ecuyer-CMRG RNG streams. In each
iteration, these seeds are set before calling FUN(x[[ii]], ...)
.
Note, for large length(x)
this may introduce a large overhead.
As input (future.seed
), a fixed seed (integer) may be given, either
as a full L'Ecuyer-CMRG RNG seed (vector of 1+6 integers) or as a seed
generating such a full L'Ecuyer-CMRG seed.
If future.seed = TRUE
, then .Random.seed
is returned if it holds a L'Ecuyer-CMRG RNG seed, otherwise one is created
randomly.
If future.seed = NA
, a L'Ecuyer-CMRG RNG seed is randomly created.
If none of the function calls FUN(x[[i]], ...)
uses random number
generation, then future.seed = FALSE
may be used.
In addition to the above, it is possible to specify a pre-generated
sequence of RNG seeds as a list such that
length(future.seed) == length(x)
and where each element is an
integer seed that can be assigned to .Random.seed
.
Use this alternative with caution.
Note that as.list(seq_along(x)) is not a valid set of such
.Random.seed
values.
In all cases but future.seed = FALSE
, the RNG state of the calling
R processes after this function returns is guaranteed to be
"forwarded one step" from the RNG state that was before the call and
in the same way regardless of future.seed
, future.scheduling
and future strategy used. This is done in order to guarantee that an R
script calling future_lapply()
multiple times should be numerically
reproducible given the same initial seed.