A collection of static methods for retrieving random values.

Constructors

Accessors

  • set randomMethod(method): void
  • Set the primary function to be called when generating any random numbers.
    Set to Math.random by default.

    Parameters

    • method: (() => number)
        • (): number
        • Returns number

    Returns void

Methods

  • Parameters

    • OptionalchanceOfTrue: number

      A floating point number between 0 and 1. If provided, it represents the percent chance that this method will return true.

    Returns boolean

    A random boolean value.

  • Type Parameters

    • Type

    Parameters

    • list: Type[]

      The list of elements to be selected from.

    Returns undefined | Type

    A random element from the given list. This method assumes an equal distribution for all elements of the list.
    If an empty list is provided, the function will return undefined.

  • Parameters

    • min: number

      The minimum number that can be returned from this function (inclusive).

    • max: number

      The maximum number that can be returned from the function (non-inclusive).

    Returns number

    A random floating point value greater than or equal to min and less than max.

  • Parameters

    • range: Range

      The Range that determines the minimum and maximum values that can be returned from the function.

    Returns number

    A random floating point value greater than or equal to Range.min and less than Range.max.

  • Parameters

    • min: number

      The minimum number that can be returned from this function (inclusive).

    • max: number

      The maximum number that can be returned from the function (non-inclusive).

    Returns number

    A random integer value greater than or equal to min and less than max.

  • Parameters

    • range: Range

      The Range that determines the minimum and maximum values that can be returned from the function.

    Returns number

    A random integer value greater than or equal to Range.min and less than Range.max.

  • Type Parameters

    • Type

    Parameters

    • list: WeightedElement<Type>[]

      The list of elements to be selected from.
      IMPORTANT: The sum of weights of the objects in this list should be equal to 1.0.

    Returns undefined | Type

    A random element from the given list. The distribution of the choices will be determined by the weights of each element in the list.
    If an empty list is provided, the function will return undefined.
    If the sum of weights in the list is less than 1.0, the function will return undefined.