Skip to content

std/random

Import: use "std/random";

Deterministic (seeded) and true random helpers.

fn choose(seed: Number, array: Array)

Deterministic element selection from an array. The same seed and array always returns the same element.

Parameters:

  • seed (Number) — integer seed value
  • array (Array) — non-empty array to choose from

Returns: Any — the selected element of array

fn choose_true(array: Array)

True random element selection from an array (uses the system clock). Different each call.

Parameters:

  • array (Array) — non-empty array to choose from

Returns: Any — the selected element of array

fn choose_weighted(seed: Number, array: Array, weights: Array)

Deterministic weighted element selection from an array. The same seed, array, and weights always returns the same element.

Parameters:

  • seed (Number) — integer seed value
  • array (Array) — non-empty array to choose from
  • weights (Array) — non-negative weights, same length as array

Returns: Any — the selected element of array, biased by weights

fn rand(seed: Number) -> Number

Deterministic random number from a seed. The same seed always returns the same value.

Parameters:

  • seed (Number) — integer seed value

Returns: Number — a pseudo-random value in [0.0, 1.0)

fn rand_true() -> Number

True random number using the system clock. Different each call.

Returns: Number — a pseudo-random value in [0.0, 1.0)