ExVrp.RNG (ExVrp v0.4.2)

Copy Markdown View Source

Random Number Generator (xoshiro128++) for deterministic, reproducible search.

This module provides a functional wrapper around PyVRP's RandomNumberGenerator. All operations return a new RNG state, preserving immutability.

Example

rng = ExVrp.RNG.new(42)
{rng, value} = ExVrp.RNG.call(rng)
{rng, float} = ExVrp.RNG.rand(rng)
{rng, int} = ExVrp.RNG.randint(rng, 100)

Summary

Functions

Generates the next random unsigned 32-bit integer.

Creates a new RNG from an explicit 4-element state.

Returns the maximum value the RNG can produce (2^32 - 1).

Returns the minimum value the RNG can produce (0).

Creates a new RNG from a seed.

Generates a random float uniformly distributed in [0, 1].

Generates a random integer in the range [0, high).

Returns the internal RNG state as a 4-element list.

Types

t()

@type t() :: reference()

Functions

call(rng)

@spec call(t()) :: {t(), non_neg_integer()}

Generates the next random unsigned 32-bit integer.

Returns {new_rng, value} where value is in the range [min(), max()].

Example

{rng, value} = ExVrp.RNG.call(rng)

from_state(state)

@spec from_state([non_neg_integer()]) :: {:ok, t()} | {:error, term()}

Creates a new RNG from an explicit 4-element state.

Example

rng = ExVrp.RNG.from_state([1, 2, 3, 4])

max()

@spec max() :: non_neg_integer()

Returns the maximum value the RNG can produce (2^32 - 1).

min()

@spec min() :: non_neg_integer()

Returns the minimum value the RNG can produce (0).

new(seed)

@spec new(non_neg_integer()) :: t()

Creates a new RNG from a seed.

Example

rng = ExVrp.RNG.new(42)

rand(rng)

@spec rand(t()) :: {t(), float()}

Generates a random float uniformly distributed in [0, 1].

Returns {new_rng, value}.

Example

{rng, float} = ExVrp.RNG.rand(rng)

randint(rng, high)

@spec randint(t(), pos_integer()) :: {t(), non_neg_integer()}

Generates a random integer in the range [0, high).

Returns {new_rng, value}.

Example

{rng, value} = ExVrp.RNG.randint(rng, 100)  # value in 0..99

state(rng)

@spec state(t()) :: [non_neg_integer()]

Returns the internal RNG state as a 4-element list.

Example

state = ExVrp.RNG.state(rng)  # [a, b, c, d]