mwg API
    Preparing search index...

    Class Generator

    The seeded generator class Random's free functions wrap directly, for a game that wants its own independent stream rather than sharing the ambient one.

    import { Generator } from '@datamoc/mw_games/core';

    const rng = new Generator(42); // same seed, same sequence, every time
    const roll = rng.int(20);
    const saved = rng.getState(); // resumable, for a save file
    Index
    seed: number
    • a float in [0, 1), with 32 bits of resolution

      Returns number

    • captures the generator state, so a save file can resume the same stream

      Returns [number, number, number, number]

    • An integer in [0, bound), without modulo bias.

      The naive nextUint32() % bound favours the low values whenever bound does not divide 2^32; this rejects the unfair tail of the range instead.

      Parameters

      • bound: number

      Returns number

    • the raw generator: a uniformly distributed unsigned 32-bit integer

      Returns number

    • Parameters

      • state: readonly [number, number, number, number]

      Returns void