Documentation
    Preparing search index...

    Class SeededRandom

    A deterministic uint32 stream (§33), seeded by a single number.

    const random = new SeededRandom(1337);
    random.nextFloat01(); // 0 <= x < 1
    random.nextRange(-Math.PI, Math.PI);
    const replay = new SeededRandom(1337); // identical sequence, forever

    See the module documentation for the generator, the seeding rule, and the five-point determinism contract. Drawing allocates nothing; only the constructor and SeededRandom.clone allocate.

    Index
    • Creates a stream from seed.

      The seed is reduced with ECMAScript's ToUint32, so it may be written as any finite number: negatives wrap (-1 is the same stream as 4294967295) and fractions truncate toward zero (1.9 is the same stream as 1). Both are deterministic, both are documented, and neither is an error.

      Parameters

      • seed: number

      Returns SeededRandom

      RangeError if seed is not a finite number — NaN and Infinity both reduce to 0 under ToUint32, which would silently collapse distinct mistakes onto one stream.

    seed: number

    The seed this stream was constructed with, reduced to a uint32. Recording this value is enough to reproduce the stream from the start.

    • A copy of this stream at its current position — not a fresh stream from the seed (use new SeededRandom(random.seed) for that). The copy and the original then advance independently, which is what makes "run the same scenario twice from here" testable, and is the whole of §34 snapshot support for an RNG.

      Returns SeededRandom

    • Next float in [0, 1) — one of 2³² equally spaced values, exactly representable (see the module note on exactness). 1 is never returned; 0 is, with probability 2⁻³².

      Returns number

    • Next float in [min, max), computed as min + (max - min) · nextFloat01().

      Not validated — this is a hot path (wander draws from it every fixed step). min === max returns min; max < min yields (max, min], the same interval traversed downwards; a non-finite bound propagates to the result. Rounding can make the result equal max only when max - min is so large that min + (max - min) · x rounds up at x just below 1, i.e. never for ranges of ordinary magnitude.

      Parameters

      • min: number
      • max: number

      Returns number

    • Next raw output: an integer in [0, 2³²), uniform over the whole range.

      This is the only method that advances the state; every other draw is derived from it, so nextFloat01() and nextRange(...) each consume exactly one output.

      Returns number

    • Rewinds the stream to its seed, so the next draw is the first one again. Returns this stream.

      Returns this