Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dot-setRNG

Setting RNG Seeds


Description

.setRNG is an S4 generic that sets the current RNG settings, from a variety of specifications. Its methods define the workhorse functions that are called by setRNG.

Usage

.setRNG(object, ...)

## S4 method for signature 'character'
.setRNG(object, ...)

## S4 method for signature 'numeric'
.setRNG(object, ...)

Arguments

object

an R object from which RNG settings can be extracted, e.g. an integer vector containing a suitable value for .Random.seed or embedded RNG data, e.g., in S3/S4 slot rng or rng$noise.

...

extra arguments to allow extension and passed to a suitable S4 method .getRNG or .setRNG.

Methods (by class)

"character": Sets the RNG to kind object, assuming is a valid RNG kind: it is equivalent to RNGkind(object, .... All arguments in ... are passed to RNGkind.

"numeric": Sets the RNG settings using object directly the new value for .Random.seed or to initialise it with set.seed.

Examples

# set RNG kind
old <- setRNG('Marsaglia')
# restore
setRNG(old)

# directly set .Random.seed
rng <- getRNG()
r <- runif(10)
setRNG(rng)
rng.equal(rng)

# initialise from a single number (<=> set.seed)
setRNG(123)
rng <- getRNG()
runif(10)
set.seed(123)
rng.equal(rng)

rngtools

Utility Functions for Working with Random Number Generators

v1.5
GPL-3
Authors
Renaud Gaujoux [aut, cre], Max Kuhn [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.