6.89. kink/random/PRNG

Pseudo random number generators using xoshiro256** algorithm.

This is a non-blocking deterministic RNG, desgined to be used for Monte Carlo simulation.

xoshiro256** is not cryptographically secure. Thus, if you have to generate such as random nonces, salts, or session ids, use kink/random/CSRNG instead.

6.89.1. type prng

`prng` is a type of pseudo RNGs based on xoshiro256** algorithm.

`prng` is a subtype of `rng`. See kink/random/RNG for `rng` type.

`prng` val is not thread-safe. Thus, use of a single `prng` val from multiple threads must be synchronized.

6.89.1.1. Prng.gen_int(Seed) .gen_bin(Size) .gen_bool

See `rng` type on kink/random/RNG mod for these methods.

6.89.1.2. Prng.state

`state` returns the internal state of the RNG as a 32 bytes `bin` val. The result bin contains at least one non-zero bit.

The result bin can be used as the arg of PRNG.from_state.

Example:

6.89.1.3. Prng.jump($config)

`jump` moves the internal state of the RNG forward by the given number of steps.

$config must take a config val, which has following methods.

• C.node(Node)

• C.thread(Thread)

• C.offset(Offset)

All the config methods take a non-negative int numer as the argument. If a method is not called, the value defaults to 0.

The number of steps will be computed as follows: Node * 2**192 + Thread * 2**128 + Offset.

Example:

6.89.2. PRNG.from_seed(Seed)

`from_seed` makes a new `prng` val from the Seed.

Preconditions:

• Seed must be an int num.

The initial state of the RNG is created as follows:

Example:

6.89.3. PRNG.from_state(State)

`from_state` makes a new `prng` val from the initial `State`.

Preconditions:

• `State` must be a `bin` val

• The size of `State` must be 32

• At least one bit of `State` must be 1

The result of Prng.state can be used as the arg of `from_state`.

Example:

6.89.4. PRNG.is?(Val)

`is?` returns whether `Val` is a `prng` val.