RNGStreams: Parallel RNG Streams

View source: R/utils.R

RNGStreamsR Documentation

Parallel RNG Streams

Description

These functions provide utilities for working with multiple streams of pseudo-random numbers.

Usage

RNGStreams(n, parallel = FALSE)

getRNGStream(env = globalenv())

setRNGStream(seed = NULL, env = globalenv())

Arguments

n

The number of RNG streams to create.

parallel

Should the RNGkind be set to the parallel-safe "L'Ecuyer-CMRG" generator if it isn't already? Note that if the RNG is set to a different generator, this will reset the random seed.

env

The environment in which to get or set the random number generator. Defaults to the global environment.

seed

A valid RNG stream to assign to .Random.seed. For safety, should be a value returned by either getRNGStream() or RNGStreams().

Value

For RNGStreams a list of length n with RNG streams for .Random.seed.

Author(s)

Kylie A. Bemis

See Also

RNGkind, nextRNGStream

Examples

# initialize parallel RNG
RNGStreams(parallel=TRUE)

# create and use RNG streams
register(SerialParam())
set.seed(1)
seeds <- RNGStreams(5)
chunkLapply(rep.int(10, 5), rnorm, seeds=seeds)

kuwisdelu/matter documentation built on May 1, 2024, 5:17 a.m.