nextRNGStream(seed)
nextRNGSubStream(seed)clusterSetRNGStream(cl = NULL, iseed)
mc.reset.stream()
.Random.seed
when the "L'Ecuyer-CMRG" RNG is in use.
See RNG
for the valid values.NULL
) the registered cluster.set.seed
, or
NULL
not to set reproducible seeds.nextRNGStream
and nextRNGSubStream
,
a value which can be assigned to .Random.seed
.RNGkind("L'Ecuyer-CMRG")
,
of L'Ecuyer (1999), which has a seed vector of 6 (signed) integers and a
period of around \(2^{191}\). Each ‘stream’ is a
subsequence of the period of length \(2^{127}\) which is in
turn divided into ‘substreams’ of length \(2^{76}\). The idea of L'Ecuyer et al (2002) is to use a separate stream
for each of the parallel computations (which ensures that the random
numbers generated never get into to sync) and the parallel
computations can themselves use substreams if required. The original
interface stores the original seed of the first stream, the original
seed of the current stream and the current seed: this could be
implemented in R, but it is as easy to work by saving the relevant
values of .Random.seed
: see the examples. clusterSetRNGStream
selects the "L'Ecuyer-CMRG"
RNG and
then distributes streams to the members of a cluster, optionally
setting the seed of the streams by set.seed(iseed)
(otherwise
they are set from the current seed of the master process: after
selecting the L'Ecuyer generator). Calling mc.reset.stream()
after setting the L'Ecuyer random
number generator and seed makes runs from
mcparallel(mc.set.seed = TRUE)
reproducible. This is
done internally in mclapply
and pvec
.
(Note that it does not set the seed in the master process, so does not
affect the fallback-to-serial versions of these functions.)RNG
for fuller details of R's built-in random number
generators. The vignette for package parallel.RNGkind("L'Ecuyer-CMRG")
set.seed(123)
(s <- .Random.seed)
## do some work involving random numbers.
nextRNGStream(s)
nextRNGSubStream(s)
Run the code above in your browser using DataLab