Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Random

Hierarchy

  • Random

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Random(initState: any, initSequence: any): Random
  • A PRNG class. Provides two main methods:

    • random - Produces a "continuous" standard uniform distribution.
    • randint - Produces a discrete uniform distribution.

    For more details, check the individual methods.

    Parameters

    • initState: any

      The seed to initialise the state of the generator.

    • initSequence: any

      The seed to initialise the sequence number of the generator.

    Returns Random

Properties

Private _inc

_inc: bigint

The sequence number of the generator.

Private _state

_state: bigint

The internal state of the generator.

Methods

_advance

  • _advance(delta: bigint): void
  • Advances the internal state of the generator delta steps. Delta can be negative to reverse.

    This is calculated in a very similar way to the square and multiply method for taking the power of a number. As you may expect, it is calculated in log(delta) time.

    Parameters

    • delta: bigint

    Returns void

_random_b

  • _random_b(): bigint
  • This is the source of randomness for all other random methods.

    Produces a uniformly distributed 32-bit unsigned integer as a bigint.

    Although the produced number is 32 bits; the implementation requires that the state of the generator be a 64 bit unsigned integer. Since the js Number datatype cannot reliably handle integers that large, we use the BigInt class for the calculation.

    Returns bigint

randint

  • randint(bound: number): number
  • Produces a uniformly distributed integer, r, with 0 ≤ r < bound.

    To produce a uniformly distributed integer in the range [low, high):

    const i = low + rand.randint(high - low)
    

    Parameters

    • bound: number

      The lower bound for the number.

    Returns number

random

  • random(): number
  • Generates an approximately uniformly distributed number, r, with 0 ≤ r < 1.

    Returns number

    The number r.

Generated using TypeDoc