Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Random

A class that produces pseudorandom numbers.

Hierarchy

  • Random

Index

Constructors

constructor

  • new Random(seed?: number): Random
  • Creates a new Random instance.

    Parameters

    • Optional seed: number

      an optional seed; if specified the Random instance will produce a reproducible sequence for testing purposes

    Returns Random

Methods

d6

  • d6(): number
  • Returns the result of rolling a simulated 6-sided die. Equivalent to pick(1,6).

    Returns number

    a random number between 1 and 6

number

  • number(): number
  • Returns a random number between 0 (inclusive) and 1 (exclusive). Effectively the same as Math.random(), but uses the random number generator of this Random object.

    Returns number

    a random number between 0 and 1

pick

  • pick(m: number, n: number): number
  • Returns a random integer between integers m and n, inclusive.

    Parameters

    • m: number

      one end of the number range

    • n: number

      the other end of the number range

    Returns number

    a random integer from m to n inclusive

pickOtherThan

  • pickOtherThan(excluded: number, m: number, n: number): number
  • Returns a random integer between m (inclusive) and n (inclusive), but excluding the value of excluded.

    throws

    if no non-excluded choice is possible

    Parameters

    • excluded: number

      the excluded integer which is never to be returned

    • m: number

      one end of the range

    • n: number

      the other end of the range

    Returns number

    a random integer from m to n inclusive, but not excluded

rollDice

  • rollDice(n: number, showDice: boolean): number[]
  • Simulates rolling n dice.

    Parameters

    • n: number

      the number of dice to roll

    • showDice: boolean

      if true, an image of each die result is printed to the console

    Returns number[]

    an array of the n rolled numbers, in the order that they were selected