Options
All
  • Public
  • Public/Protected
  • All
Menu

@spissvinkel/alea - v1.2.1

Index

Functions

Const emptyState

  • Creates an uninitialized PRNG state object. Must be initialized with initState before use

    Returns AleaState

    a new, uninitialized state object

Const fract53

  • Parameters

    • state: AleaState

      a state object, probably generated with mkState. Will be updated as a side effect

    Returns number

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

Const initState

  • Initializes a recycled PRNG state object using the provided seed value

    Parameters

    • seed: string

      a seed value

    • state: AleaState

      a state object to initialize

    Returns AleaState

    the provided state object initialized using the provided seed

Const mkAlea

  • Initialize a new PRNG

    Parameters

    • seed: string = ...

      an optional seed value

    Returns AleaPRNG

    an initialized PRNG

Const mkState

  • Initializes a new PRNG state object using the provided seed value

    Parameters

    • seed: string

      a seed value

    Returns AleaState

    a new state object based on the provided seed

Const nextT

  • nextT<T>(f: (n: number) => T): (state: AleaState) => T
  • 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: number) => T

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

        • (n: number): T
        • Parameters

          • n: number

          Returns T

    Returns (state: AleaState) => T

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

      • Parameters

        • state: AleaState

          a state object, probably generated with mkState. Will be updated as a side effect

        Returns T

Const random

  • Parameters

    • state: AleaState

      a state object, probably created with mkState. Will be updated as a side effect

    Returns number

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

Const restoreAlea

  • Initialize a new PRNG from a previously saved state, effectively allowing the previous PRNG to be resumed

    Parameters

    Returns AleaPRNG

    an initialized PRNG

Const uint32

  • Parameters

    • state: AleaState

      a state object, probably generated by mkState. Will be updated as a side effect

    Returns number

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

Generated using TypeDoc