RNGStream: S3 class to work with RngStream objects

View source: R/rcpp_hello_world.R

RNGStreamR Documentation

S3 class to work with RngStream objects

Description

S3 class to work with RngStream objects

Use RNGStream as an old class

With method for RNGStream S3 class

Usage

RNGStream(nextStream = TRUE, iseed = NULL)

## S3 method for class 'RNGStream'
with(data, expr, ...)

Arguments

nextStream

whether to move to the next stream (default=TRUE)

iseed

set seed after changing RNG (otherwise keep the current seed)

data

object of type RNGStream

expr

expression using the RNGStream

...

other arguments passed to eval()

Value

list of class RNGStream with components:

resetRNGkind

function to reset to the previous RNG and seed

seed

function to return the current seed

itemopenfunction to use the current seed itemclosefunction to make the current seed equal to .Random.seed itemresetStreamfunction to move back to start of stream itemresetSubStreamfunction to move back to start of sub-stream itemnextSubStreamfunction to move to next sub-stream itemnextStreamfunction to move to next stream

the value from the expression

Examples

## set up one stream
s1 <- RNGStream()
s1$open()
rnorm(1)
s1$nextSubStream()
rnorm(1)
## reset the stream
s1$resetStream()
rnorm(2)
s1$nextSubStream()
rnorm(2)

## now do with two streams
s1$resetStream()
s2 <- RNGStream()
with(s1,rnorm(1))
with(s2,rnorm(1))
s1$nextSubStream()
with(s1,rnorm(1))
## now reset the streams and take two samples each time
s1$resetStream()
s2$resetStream()
with(s1,rnorm(2))
with(s2,rnorm(2))
s1$nextSubStream()
with(s1,rnorm(2))

microsimulation documentation built on July 26, 2023, 6:10 p.m.