jetlag2d
    Preparing search index...

    Class RandomService

    Random is a seedable pseudo-random number generator. Unlike Math.random(), reseeding with the same number and making the same sequence of calls always produces the same sequence of results, which is useful for procedural level generation you want to be reproducible

    If you don't care about reproducibility, you don't need to seed it at all: the constructor picks a seed from the clock, so an unseeded RandomService still behaves like an ordinary random number generator.

    Index
    • A pseudo-randomly chosen element of choices

      Type Parameters

      • T

      Parameters

      • choices: T[]

        A non-empty array to choose from

      Returns T

    • The next pseudo-random number, uniformly distributed in [0, 1).

      This is mulberry32, a small, fast PRNG that's more than good enough for games (though not for cryptography).

      Returns number

    • A pseudo-random boolean

      Parameters

      • probability: number = 0.5

        The chance of returning true (default 0.5)

      Returns boolean

    • A pseudo-random integer in [0, maxExclusive)

      Parameters

      • maxExclusive: number

        The exclusive upper bound

      Returns number

    • A pseudo-random integer in [minInclusive, maxExclusive)

      Parameters

      • minInclusive: number

        The inclusive lower bound

      • maxExclusive: number

        The exclusive upper bound

      Returns number

    • Reset the generator to start over from seed. Calling reseed(1234) and then making the same sequence of next()/nextInt()/etc. calls will always produce the same sequence of results.

      Parameters

      • seed: number

        The seed to restart from

      Returns void