Learn R Programming

itertools (version 0.1-3)

iRNGStream: Iterators that support parallel RNG

Description

The iRNGStream function creates an infinite iterator that calls nextRNGStream repeatedly, and iRNGSubStream creates an infinite iterator that calls nextRNGSubStream repeatedly.

Usage

iRNGStream(seed) iRNGSubStream(seed)

Arguments

seed
Either a single number to be passed to set.seed or a vector to be passed to nextRNGStream or nextRNGSubStream.

See Also

set.seed, nextRNGStream, nextRNGSubStream

Examples

Run this code
it <- iRNGStream(313)
print(nextElem(it))
print(nextElem(it))

## Not run: 
# library(foreach)
# foreach(1:3, rseed=iRNGSubStream(1970), .combine='c') %dopar% {
#   RNGkind("L'Ecuyer-CMRG") # would be better to initialize workers only once
#   assign('.Random.seed', rseed, pos=.GlobalEnv)
#   runif(1)
# }
# ## End(Not run)

Run the code above in your browser using DataLab