Class for creating random values, supporting Javascript's Math.random and a deterministig pseudo-random number generator (PRNG) that can be fed with a seed and then returns a reproducable set of random numbers (if the precision of Javascript allows)

Author

Jirka Dell'Oro-Friedl, HFU, 2019

Constructors

  • Create an instance of Random. If a seed is given, LFIB4 is used as generator, reproducing a series of numbers from that seed. If a function producing values between 0 and 1 is given, it will be used as generator.

    Parameters

    • Optional _seedOrFunction: number | Function

    Returns Random

Properties

default: Random = ...

Methods

  • Returns a randomly selected element of the given array

    Type Parameters

    • T

    Parameters

    • _array: T[]

    Returns T

  • Returns a randomly selected index into the given array

    Type Parameters

    • T

    Parameters

    • _array: T[]

    Returns number

  • Returns a randomly selected property name from the given object

    Type Parameters

    • T

    Parameters

    • _object: T

    Returns keyof T

  • Returns a randomly selected symbol from the given object, if symbols are used as keys

    Type Parameters

    • T

    Parameters

    • _object: T

    Returns symbol

  • Returns a random number in the range of given [_min, _max[

    Parameters

    • _min: number
    • _max: number

    Returns number

  • Returns a random integer number in the range of given floored [_min, _max[

    Parameters

    • _min: number
    • _max: number

    Returns number

  • Removes a randomly selected element from the given array and returns it

    Type Parameters

    • T

    Parameters

    • _array: T[]

    Returns T