Skip to contents

This function exists to support use from other packages that wish to use monty's random number support, and creates an opaque pointer to a set of random number streams.

Public fields

algorithm

The name of the generator algorithm used (read-only)

n_streams

The number of streams of random numbers provided (read-only)

Methods


Method new()

Create a new monty_rng_pointer object

Usage

monty_rng_pointer$new(
  seed = NULL,
  n_streams = 1L,
  long_jump = 0L,
  algorithm = "xoshiro256plus"
)

Arguments

seed

The random number seed to use (see monty_rng for details)

n_streams

The number of independent random number streams to create

long_jump

Optionally an integer indicating how many "long jumps" should be carried out immediately on creation. This can be used to create a distributed parallel random number generator (see monty_rng_distributed_state)

algorithm

The random number algorithm to use. The default is xoshiro256plus which is a good general choice


Method sync()

Synchronise the R copy of the random number state. Typically this is only needed before serialisation if you have ever used the object.

Usage

monty_rng_pointer$sync()


Method state()

Return a raw vector of state. This can be used to create other generators with the same state.

Usage

monty_rng_pointer$state()


Method is_current()

Return a logical, indicating if the random number state that would be returned by state() is "current" (i.e., the same as the copy held in the pointer) or not. This is TRUE on creation or immediately after calling $sync() or $state() and FALSE after any use of the pointer.

Usage

monty_rng_pointer$is_current()

Examples

monty::monty_rng_pointer$new()
#> <monty_rng_pointer>
#>   Public:
#>     algorithm: xoshiro256plus
#>     initialize: function (seed = NULL, n_streams = 1L, long_jump = 0L, algorithm = "xoshiro256plus") 
#>     is_current: function () 
#>     n_streams: 1
#>     state: function () 
#>     sync: function () 
#>   Private:
#>     is_current_: TRUE
#>     ptr_: externalptr
#>     state_: f7 f5 a5 ce 4f db 8c e3 61 72 35 b8 54 9f 1a 92 2e 06 d4 ...