Skip to content

std/random

Import: use "std/random";

Deterministic (seeded) and true random helpers.

fn choose(seed: Number, array: Array<Any>) -> Any

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<Any>) -> Any

True random element selection from an array, drawn from the operating system’s entropy. Different each call and each run, from the first call on.

Parameters:

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

Returns: Any — the selected element of array

fn choose_weighted(seed: Number, array: Array<Any>, weights: Array<Number>) -> Any

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, drawn from the operating system’s entropy. Different each call and each run, from the first call on.

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