Skip to main content

Class: RandomDraws

Constructors

new RandomDraws()

new RandomDraws(): RandomDraws

Returns

RandomDraws

Methods

fromGridWithoutReplacement()

static fromGridWithoutReplacement(n, rows, columns, predicate?): object[]

Draw random grid cell locations, without replacement, from a uniform distribution of all grid cells. Grid cell locations are zero-based, i.e., upper-left is (0,0).

Parameters

n: number

Number of draws

rows: number

Number of rows in grid; must be at least 1

columns: number

Number of columns in grid; must be at least 1

predicate?

Optional lambda function that takes a grid row number and grid column number pair and returns a boolean to indicate if the pair should be allowed. For example, if one wanted to constrain the random grid location to be along the diagonal, the predicate would be: (row, column) => row === column

Returns

object[]

Array of grid cells. Each cell is object in form of: &#123 row: number, column: number }. Grid cell locations are zero-based

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:181


FromGridWithoutReplacement()

static FromGridWithoutReplacement(n, rows, columns, predicate?): object[]

Parameters

n: number

rows: number

columns: number

predicate?

Returns

object[]

Deprecated

Use fromGridWithoutReplacement() instead.

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:218


fromRangeWithoutReplacement()

static fromRangeWithoutReplacement(n, minimumInclusive, maximumInclusive): number[]

Draws random integers, without replacement, from a uniform distribution of integers in the specified range.

Parameters

n: number

Number of draws

minimumInclusive: number

Lower bound of range

maximumInclusive: number

Upper bound of range

Returns

number[]

An array of integers

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:113


FromRangeWithoutReplacement()

static FromRangeWithoutReplacement(n, minimumInclusive, maximumInclusive): number[]

Parameters

n: number

minimumInclusive: number

maximumInclusive: number

Returns

number[]

Deprecated

Use fromRangeWithoutReplacement() instead.

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:153


random()

static random(): number

Generates a random number in the range [0, 1) using the current random function.

Returns

number

A random number in the range [0, 1) using the current random function.

Remarks

This method will return a number from Math.random() in the runtime environment, unless setSeed() has been called to initialize a seeded PRNG.

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:58


setSeed()

static setSeed(seed): void

Sets the seed for the pseudo-random number generator (PRNG) and instructs methods within RandomDraws to use a seeded PRNG instead of the default Math.random().

Parameters

seed: string

The seed string to initialize the PRNG.

Returns

void

Remarks

The implementation of the seeded PRNG is based on David Bau's seedrandom library at https://github.com/davidbau/seedrandom

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:18


singleFromRange()

static singleFromRange(minimumInclusive, maximumInclusive): number

Draws a single random integer from a uniform distribution of integers in the specified range.

Parameters

minimumInclusive: number

Lower bound of range

maximumInclusive: number

Upper bound of range

Returns

number

A sampled integer

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:70


SingleFromRange()

static SingleFromRange(minimumInclusive, maximumInclusive): number

Parameters

minimumInclusive: number

maximumInclusive: number

Returns

number

Deprecated

Use singleFromRange() instead.

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:97


useDefaultRandom()

static useDefaultRandom(): void

Instructs methods within RandomDraws to use the default Math.random() from the runtime environment as the random number function instead of a seeded PRNG.

Returns

void

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:28


useSeededRandom()

static useSeededRandom(): void

Instructs methods within RandomDraws to use the seeded pseudo-random number generator (PRNG).

Returns

void

Remarks

This method will throw an error if setSeed() has not been called first to initialize the seeded PRNG.

Defined in

m2c2kit/packages/core/src/RandomDraws.ts:39