Rng

Rng

A seeded random source with the draw operations the pipeline uses. Construct via createRng (which fills in a random seed when none is given).

Constructor

new Rng(seed)

Source:
Parameters:
Name Type Description
seed string | number

The seed (a number is stringified). Recorded as Rng#seed.

Classes

Rng

Methods

chance(p) → {boolean}

Source:
Parameters:
Name Type Description
p number

Probability in [0, 1].

Returns:

True with probability p.

Type
boolean

float() → {number}

Source:
Returns:

The next float in [0, 1).

Type
number

fork(labelopt) → {Rng}

Description:
  • Derive an independent, deterministic sub-stream. Two forks of the same parent with the same label are identical; different labels (or the auto-incrementing counter) diverge — used to give each prompt in a batch its own reproducible sequence without them sharing draws.

Source:
Parameters:
Name Type Attributes Description
label string | number <optional>

A stable label; defaults to an incrementing counter.

Returns:

The child generator.

Type
Rng

int(min, max) → {number}

Source:
Parameters:
Name Type Description
min number

Inclusive lower bound.

max number

Inclusive upper bound (order-tolerant).

Returns:

A uniform integer in [min, max].

Type
number

pick(arr) → {T}

Source:
Parameters:
Name Type Description
arr Array.<T>

A non-empty array.

Returns:

A uniformly random element (undefined for an empty array).

Type
T

sample()

Description:
  • Alias of Rng#pick — matches the sample helper name.

Source:

shuffle(arr) → {Array.<T>}

Source:
Parameters:
Name Type Description
arr Array.<T>

The source array (not mutated).

Returns:

A new array in uniformly random order (Fisher–Yates).

Type
Array.<T>