Function mersenneTwister

  • Reproducible random values using the Merseene Twister algorithm. With the same seed value, it produces the same series of random values.

    // Seed with a value of 100
    const r = mersenneTwister(100);
    r.float(); // 0..1

    Integer values can also be produced. First parameter is the maximum value (exclusive), the optional second parameter is the minimum value (inclusive).

    r.integer(10);     // 0..9
    r.integer(10, 5); // 5..9

    // Eg random array index:
    r.integer(someArray.length);

    Adapted from George MacKerron's implementation. MIT License. https://github.com/jawj/mtwist/

    Parameters

    • Optionalseed: number

      Seed value 0..4294967295. Default: random seed.

    Returns {
        float: (() => number);
        integer: ((maxExclusive: number, minInclusive?: number) => number);
    }

    • float: (() => number)
        • (): number
        • Returns number

    • integer: ((maxExclusive: number, minInclusive?: number) => number)
        • (maxExclusive, minInclusive?): number
        • Parameters

          • maxExclusive: number
          • minInclusive: number = 0

          Returns number