Function nextT

  • Creates utility functions based on the [[random]] function, e.g.:

    const state: AleaState = mkState('123');
    const nextBool: (state: AleaState) => boolean = nextT(n => n < 0.5);
    // calling `nextBool(state)` now returns `true` or `false` at random

    Type Parameters

    • T

    Parameters

    • f: ((n) => T)

      a function to transform a number in the interval [0, 1) to a value of type T

        • (n): T
        • Parameters

          • n: number

          Returns T

    Returns ((state) => T)

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

      • (state): T
      • Parameters

        Returns T

Generated using TypeDoc