Interface AleaPRNG

An Alea PRNG

Hierarchy

  • AleaPRNG

Properties

random: (() => number)

Type declaration

    • (): number
    • Returns number

      a pseudo-random floating-point number in the interval [0, 1) (like Math.random())

uint32: (() => number)

Type declaration

    • (): number
    • Returns number

      a pseudo-random unsigned 32-bit integer in the interval [0, 2^32)

fract53: (() => number)

Type declaration

    • (): number
    • Returns number

      a pseudo-random full 53-bit fraction in the interval [0, 1). (Slower than [[AleaPRNG.random]] but higher precision)

nextT: (<T>(f) => (() => T))

Type declaration

    • <T>(f): (() => T)
    • Creates utility functions based on this PRNG, e.g.:

      const alea: AleaPRNG = mkAlea();
      const nextBool: () => boolean = alea.nextT(n => n < 0.5);
      // calling `nextBool()` now returns `true` or `false` at random

      Type Parameters

      • T

      Parameters

      • f: ((n) => T)
          • (n): T
          • Parameters

            • n: number

            Returns T

      Returns (() => T)

      a function that, when invoked, transforms the next pseudo-random number n to a T using the provided function f

        • (): T
        • Returns T

getState: (() => AleaState)

Type declaration

    • (): AleaState
    • Returns AleaState

      a copy of the current state of this PRNG, which can be saved and then later passed to the [[restoreAlea]] function

Generated using TypeDoc