Learn R Programming

rlecuyer (version 0.3-8)

CurrentStream: 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"))

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.

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.

Examples

Run this code
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)
}

Run the code above in your browser using DataLab