Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AleaRNG

AleaRNG is an implementation based on https://github.com/nquinlan/better-random-numbers-for-javascript-mirror Johannes Baagøe baagoe@baagoe.com, 2010

Hierarchy

  • AleaRNG

Implements

Index

Constructors

constructor

  • new AleaRNG(seed?: undefined | string): AleaRNG
  • Creates a new AleaRNG

    Parameters

    • Optional seed: undefined | string

      An optional string to seed the generation. Defaults to new Date() if not provided.

    Returns AleaRNG

Methods

clone

  • Returns a copy of the AleaRNG, with the seed and current step value.

    Returns AleaRNG

    • A copy of the AleaRNG

next

  • next(min?: number, max?: number): number
  • Returns a number between [min, max). Use nextInt() for integers.

    Parameters

    • Default value min: number = 0

      The min (inclusive). Default 0.

    • Default value max: number = 1

      The max (exclusive). Default 1.

    Returns number

    • A float between [min, max)

nextBoolean

  • nextBoolean(): boolean

nextInt

  • nextInt(min?: number, max?: number): number
  • Returns an integer between [min, max). Use next() for floats.

    Parameters

    • Default value min: number = 0

      The min (inclusive). Default 0.

    • Default value max: number = 100

      The max (exclusive). Default 100.

    Returns number

    • An integer between [min, max)

nextItem

  • nextItem<T>(array: T[]): T | undefined
  • Returns a random item from the given array. This does not remove the item from the array, and multiple calls with the same array may yield the same item. If looking to randomize an array, use shuffle().

    Type parameters

    • T

    Parameters

    • array: T[]

      An array of items.

    Returns T | undefined

    • A single item from the array.

reset

  • reset(): void

shuffle

  • shuffle<T>(array: T[]): T[]
  • Shuffles all values inside an array. Returns a copy, and does not edit the original.

    Type parameters

    • T

    Parameters

    • array: T[]

      An array of items

    Returns T[]

    • A clone of the original array with all values shuffled.

Generated using TypeDoc