Pseudo-Random Number Generator (PRNG) class.

Constructors

Properties

_seed: number = DEFAULT_SEED

Accessors

  • set seed(value): void
  • Sets the seed value for the Pseudorandom Number Generator (PRNG). If the value is undefined, the current timestamp is used as the seed.

    Parameters

    • value: string | number

      The value to use for seeding.

    Returns void

Methods

  • Generate a random number with a Gaussian distribution.

    Returns number

    A random number with a Gaussian distribution.

  • Hashes the input value for use in seeding.

    Parameters

    • value: string | number

      The input value to be hashed.

    Returns number

    The hashed value.

  • Generates the next pseudo-random number in the sequence.

    Returns number

    The next pseudo-random number (float) in the sequence.

  • Generate a normalized random number within a range.

    Parameters

    • minValue: number

      The minimum value.

    • maxValue: number

      The maximum value.

    Returns number

    A normalized random number within the specified range.

  • Generates a pseudo-random number within the specified range.

    Parameters

    • lowerBound: number = 0

      The lower bound of the range.

    • upperBound: number = 1

      The upper bound of the range.

    Returns number

    A pseudo-random number within the specified range or from range [0,1]

  • Randomly choose an element from an array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array with elements to choose from.

    Returns T

    A randomly chosen element from the array.

  • Generates a pseudo-random number that is either -1 or 1.

    Returns number

    -1 or 1.

  • Generate a weighted random number based on a function.

    Parameters

    • func: ((value) => number)

      The weighting function.

        • (value): number
        • Parameters

          • value: number

          Returns number

    Returns number

    A weighted random number.