Shared base deriving the whole Rng surface from a single stateful primitive, nextUint32. Subclasses implement nextUint32 (the raw 32-bit generator) plus seed/getState/setState; float, uint32, int, and die are unbiased by construction here.

Hierarchy (View Summary)

Implements

Constructors

Methods

  • A uniform die roll in [1, sides].

    Parameters

    • sides: number

      Number of faces; must be >= 1.

    Returns number

    An integer 1 <= n <= sides.

    If sides < 1.

  • A uniform float in [0, 1) at 32-bit resolution (like Math.random).

    Returns number

    A pseudo-random number, 0 <= n < 1.

  • Snapshot the internal state so it can be restored with setState (e2e captures before an action, replays after).

    Returns number[]

    A copy of the generator's state words — mutating it is safe.

  • A uniform integer in [min, max], inclusive on both ends.

    Parameters

    • min: number

      Inclusive lower bound.

    • max: number

      Inclusive upper bound; must be >= min.

    Returns number

    An integer min <= n <= max.

    If max < min.

  • Fully reset the stream to a known start (reset, not perturb). String seeds hash through cyrb128, so seeding each unit test with its own name gives an independent, reproducible stream for free.

    Parameters

    • seed: string | number | number[]

      A string, a single number, or the four state words directly.

    Returns void

  • Restore state previously produced by getState. Unlike seed, this sets the exact words with no re-mixing.

    Parameters

    • state: number[]

      The four state words to restore.

    Returns void

    If state does not hold four words.

  • A uniform integer in [0, bound), unbiased (rejection-sampled — no modulo/rounding skew, which matters on d100-scale hit-location tables).

    Parameters

    • bound: number

      Exclusive upper bound; must be >= 1.

    Returns number

    An integer 0 <= n < bound.

    If bound < 1.