make_rng_seeds: Produce Reproducible Seeds for Parallel Random Number...

View source: R/make_rng_seeds.R

make_rng_seedsR Documentation

Produce Reproducible Seeds for Parallel Random Number Generation

Description

Produce Reproducible Seeds for Parallel Random Number Generation

Usage

make_rng_seeds(count, seed = FALSE)

Arguments

count

The number of RNG seeds to produce.

seed

A logical specifying whether RNG seeds should be generated or not. (seed = NULL corresponds to seed = FALSE). If a list, then it should be of length count and each element should consist of a valid RNG seed.

Details

This function generates count independent L'Ecuyer-CMRG random seeds that can be used as .Random.seed for parallel processing. These seeds are produced with help of parallel::nextRNGSubStream() and parallel::nextRNGStream() using a strategy that

seed <- <initial RNG seed>
for (ii in seq_len(count)) {
  seeds[[ii]] <- parallel::nextRNGSubStream(seed)
  seed <- parallel::nextRNGStream(seed)
}

This function forwards the RNG state 1 + count times if seed = TRUE.

Value

Returns a non-named list of count independent L'Ecuyer-CMRG random seeds. If seed is NULL or FALSE, then NULL is returned.

Examples

## Set up L'Ecuyer-CMRG random seeds for 100 parallel tasks
## based on .Random.seed in the current R process
seeds <- make_rng_seeds(100L, seed = TRUE)
str(seeds)

HenrikBengtsson/future.mapreduce documentation built on April 14, 2025, 10:27 a.m.