RNGseed: Directly Getting or Setting the RNG Seed

Description Usage Arguments Value Functions Examples

View source: R/RNG.R

Description

These functions provide a direct access to the RNG seed object .Random.seed.

Usage

1
2
3

Arguments

seed

an RNG seed, i.e. an integer vector. No validity check is performed, so it must be a valid seed.

Value

invisibly the current RNG seed when called with no arguments, or the – old – value of the seed before changing it to seed.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#--- RNGseed ---

# get current seed
RNGseed()
# directly set seed
old <- RNGseed(c(401L, 1L, 1L))
# show old/new seed description
showRNG(old)
showRNG()

# set bad seed
RNGseed(2:3)
try( showRNG() )
# recover from bad state
RNGrecovery()
showRNG()

# example of backup/restore of RNG in functions
f <- function(){
	orng <- RNGseed()
 on.exit(RNGseed(orng))
	RNGkind('Marsaglia')
	runif(10)
}

sample(NA)
s <- .Random.seed
f()
identical(s, .Random.seed)

renozao/rngtools documentation built on Sept. 24, 2021, 11:14 p.m.