mwg API
    Preparing search index...

    Class MersenneTwister

    MT19937, the Mersenne Twister the reference strategy game's mt_rng wraps, with the same seed/discard bookkeeping its save files use. The engine itself is exactly specified (the paper's constants and the 32-bit seeding routine), so nextUint32 matches that engine bit for bit on any machine; a port that consumes the raw stream, or a replay of raw draws, lines up.

    What is not portable is C++'s std::uniform_int_distribution, which the reference then runs the engine through: the C++ standard leaves that mapping implementation-defined, so two standard libraries do not agree on it. int here is the same unbiased rejection Generator uses, which makes a replay deterministic within this framework rather than bit-identical to any one C++ standard library.

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

    const rng = new MersenneTwister(5489);
    const first = rng.nextUint32(); // 3499211612, the engine's own first value for this seed
    rng.discard(10); // skip ahead without consuming the values
    const saved = rng.getState(); // { seed, state, index, discard } - restorable
    Index
    • get discardCount(): number

      how many values have been produced since the last seed - get_discard()'s number

      Returns number

    • advances the engine without using the values, as mt_rng::discard does

      Parameters

      • count: number

      Returns void

    • a float in [0, 1), with 32 bits of resolution

      Returns number

    • an integer in [0, bound), without modulo bias (the same rule Generator.int uses)

      Parameters

      • bound: number

      Returns number

    • the raw generator, tempered as MT19937 specifies

      Returns number

    • re-seeds the engine and resets the discard count, as mt_rng::seed does

      Parameters

      • seed: number

      Returns void