setRNG: Set the Random Number Generator

Description Usage Arguments Details Value Side Effects See Also Examples

View source: R/setRNG.R

Description

Set the RNG or return information about the setting of the RNG.

Usage

1
2
    setRNG(kind=NULL, seed=NULL, normal.kind=NULL)
    

Arguments

None required

kind

a character string.

seed

a vector of numbers (depending on kind).

normal.kind

a character string.

Details

Sets the uniform and normal random number generators and the seed. The old setting is returned using invisible() in a format which can be used in another call to setRNG. (This would reset to the original value.) If no arguments are given the current setting is returned, not using invisible(). In R see RNGkind for more details.

Note that in a function using setRNG it is good practice to assign the old setting to a variable, then reset to the old value on exiting the function (using on.exit). This avoids the possibility that overall RNG behaviour in a session, other than within your function, may be disrupted by your function.

Value

The old setting.

Side Effects

Sets global variables controlling the uniform and normal random number generators and the global seed.

See Also

RNGkind, set.seed, runif, rnorm, random.number.test

Examples

1
2
setRNG(kind="Wichmann-Hill", seed=c(979,1479,1542), normal.kind="Box-Muller")
rnorm(10)

setRNG documentation built on May 2, 2019, 5:22 p.m.