mwg API
    Preparing search index...

    Class JavaRandom

    The 48-bit linear congruential generator behind java.util.Random, bit for bit, so a game ported from the JVM can replay the same seed and get the same dungeon. The algorithm is the one the Java documentation specifies; every method below follows that specification, including the rejection loop of nextInt(bound).

    Not a good general generator (use Generator for that): its only job is to agree with Java. Seeds may be numbers or bigints; a 64-bit seed keeps its low 48 bits after the documented scramble.

    import { JavaRandom } from '@datamoc/mwg/core';

    const random = new JavaRandom(42);
    console.log(random.nextInt()); // -1170105035, what `new Random(42).nextInt()` returns
    console.log(random.nextInt(100)); // an int in 0..99
    Index
    • the next bits (1 to 32) pseudorandom bits; a 32-bit draw is signed, as in Java

      Parameters

      • bits: number

      Returns number

    • With no argument, any int (nextInt()); with a positive bound, an int in [0, bound) (nextInt(bound)), drawn without modulo bias the way Java does.

      Parameters

      • Optionalbound: number

      Returns number

    • a signed 64-bit integer, two 32-bit draws combined as Java does

      Returns bigint

    • restarts the sequence, as Random.setSeed does

      Parameters

      • seed: number | bigint

      Returns void