Options
All
  • Public
  • Public/Protected
  • All
Menu

Pseudo-random number generator following the Mersenne_Twister algorithm. Given a seed this generator will produce the same sequence of numbers each time it is called. See https://en.wikipedia.org/wiki/Mersenne_Twister for more details. Uses the MT19937-32 (2002) implementation documented here http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

Api inspired by http://chancejs.com/# https://github.com/chancejs/chancejs

Hierarchy

  • Random

Index

Constructors

constructor

  • new Random(seed?: number): Random

Properties

Optional seed

seed: number

Methods

bool

  • bool(likelihood?: number): boolean
  • Returns true or false randomly with 50/50 odds by default. By default the likelihood of returning a true is .5 (50%).

    Parameters

    • Default value likelihood: number = 0.5

      takes values between [0, 1]

    Returns boolean

d10

  • d10(): number

d12

  • d12(): number

d20

  • d20(): number

d4

  • d4(): number

d6

  • d6(): number

d8

  • d8(): number

floating

  • floating(min: number, max: number): number
  • Return a random floating point in range [min, max) min is included, max is not included

    Parameters

    • min: number
    • max: number

    Returns number

integer

  • integer(min: number, max: number): number

next

  • next(): number

nextInt

  • nextInt(): number

pickOne

  • pickOne<T>(array: Array<T>): T

pickSet

  • pickSet<T>(array: Array<T>, numPicks: number, allowDuplicates?: boolean): Array<T>
  • Returns a new array random picking elements from the original

    Type parameters

    • T

    Parameters

    • array: Array<T>

      Original array to pick from

    • numPicks: number

      can be any positive number

    • Default value allowDuplicates: boolean = false

      indicates whether the returned set is allowed duplicates (it does not mean there will always be duplicates just that it is possible)

    Returns Array<T>

range

  • range(length: number, min: number, max: number): Array<number>
  • Generate a list of random integer numbers

    Parameters

    • length: number

      the length of the final array

    • min: number

      the minimum integer number to generate inclusive

    • max: number

      the maximum integer number to generate inclusive

    Returns Array<number>

shuffle

  • shuffle<T>(array: Array<T>): Array<T>