CurrentStream: Set/unset the current stream

CurrentStreamR Documentation

Set/unset the current stream

Description

.lec.CurrentStream sets the current stream for usage with the standard R functions for generating random numbers such as runif or rnorm. .lec.CurrentStreamEnd unsets it.

Usage

.lec.CurrentStream (name)
.lec.CurrentStreamEnd (kind.old = c("Mersenne-Twister",
                         "Kinderman-Ramage"))

Arguments

name

a character string giving the name of the stream.

kind.old

a length 2 character vector, the old rng kinds (possiblly returned by .lec.CurrentStream).

Details

.lec.CurrentStream sets the RNGkind to user-defined. All succeeding calls of R built-in genertors will generate random numbers from the stream name, until .lec.CurrentStreamEnd is called. .lec.CurrentStreamEnd updates the RNG state of the stream name in the table .lec.Random.seed.table and sets the RNGkind to kind.old. These two functions are meant to be always used as a pair. Thus, one can arbitrarily switch generating between different streams.

Value

.lec.CurrentStream returns a two-element character vector of the RNG and normal kinds in use before the call. .lec.CurrentStreamEnd returns a character string giving the name of the unset current stream.

Examples

nstreams <- 10       # number of streams
names <- paste("mystream",1:nstreams,sep="")
.lec.CreateStream(names)
for (i in 1:nstreams) {  # generate 10 RNs from each stream
   old.kind <- .lec.CurrentStream(names[i])
   print(paste("stream no.",i))
   print(runif(10))
   .lec.CurrentStreamEnd(old.kind)
}

rlecuyer documentation built on March 31, 2023, 5:54 p.m.