random_stream: Creates an environment (similar to R6 class) of random...

View source: R/input_f.R

random_streamR Documentation

Creates an environment (similar to R6 class) of random uniform numbers to be drawn from

Description

Creates an environment (similar to R6 class) of random uniform numbers to be drawn from

Usage

random_stream(stream_size = 100)

Arguments

stream_size

Length of the vector of random uniform values to initialize

Details

This function creates an environment object that behaves similar to an R6 class but offers more speed vs. an R6 class.

The object is always initialized (see example below) to a specific vector of random uniform values. The user can then call the object with obj$draw_number(n), where n is an integer, and will return the first n elements of the created vector of uniform values. It will automatically remove those indexes from the vector, so the next time the user calls obj$draw_n() it will already consider the next index.

The user can also access the latest elements drawn by accessing obj$random_n (useful for when performing a luck adjustment), the current stream still to be drawn using obj$stream and the original size (when created) using obj$stream_size.

If performing luck adjustment, the user can always modify the random value by using obj$random_n <- luck_adj(...) (only valid if used with the expression approach, not with modify_item)

Value

Self (environment) behaving similar to R6 class

Examples

stream_1 <- random_stream(1000)
number_1 <- stream_1$draw_n() #extract 1st index from the vector created
identical(number_1,stream_1$random_n) #same value
number_2 <- stream_1$draw_n() #gets 1st index (considers previous)
identical(number_2,stream_1$random_n) #same value

WARDEN documentation built on June 11, 2025, 5:08 p.m.