Class: PRNG

PRNG(optionsopt)

new PRNG(optionsopt)

Creates an instance of PRNG.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

The configuration options for the PRNG.

Properties
Name Type Attributes Default Description
seed number <optional>
Date.now()

The default seed value for the PRNG is the current timestamp.

algorithm PRNGAlgorithm <optional>
XORShift32

The algorithm to use for generating psuedo-random numbers.

Source:

Classes

PRNG

Methods

randomBipolarFloat() → {number}

Generate a random float in the range [-1, 1).

Source:
Returns:

A number between -1 (inclusive) and 1 (exclusive).

Type
number

randomChance(chanceopt) → {boolean}

Returns a boolean based on a specified probability.

Parameters:
Name Type Attributes Default Description
chance number <optional>
0.5

The probability of returning true (between 0 and 1).

Source:
Returns:

True if the random float is less than the chance, otherwise false.

Type
boolean

randomElement(array) → {*}

Select a random element from an array.

Parameters:
Name Type Description
array array

The array from which to select an element.

Source:
Returns:

A randomly selected element from the array.

Type
*

randomFloat(maxopt, minopt) → {number}

Generate a random float in the range [0, 1).

Parameters:
Name Type Attributes Default Description
max number <optional>
1

A single argument specifies a range of between 0 and that number.

min number <optional>
0

Two numeric arguments specifies a range.

Source:
Returns:

A floating-point number in a given range, 0 (inclusive) and 1 (exclusive) if called without arguments.

Type
number

randomGaussian(meanopt, sdopt) → {number}

Generate a random float that fits a normal distribution.

The most likely values are at the mean. The standard deviation describes the spread of the distribution.

With a mean of 0, and standard deviation of 1 (default values);

  • 68% of results fall within +/- 1
  • 95% of results fall within +/- 2
  • 99% of results fall within +/- 3
Parameters:
Name Type Attributes Default Description
mean number <optional>
0

The mean of the distribution.

sd number <optional>
1

The standard deviation of the distribution.

Source:
Returns:
Type
number

randomInteger(min, max) → {number}

Generate a random integer from a specified range of values.

Parameters:
Name Type Description
min number

The minimum integer value (inclusive).

max number

The maximum integer value (exclusive).

Source:
Returns:

A random integer between min (inclusive) and max (exclusive).

Type
number

randomSample(array, size) → {array}

Returns a sample without replacement from a given array and sample size.

Parameters:
Name Type Description
array array

The array from which to sample elements.

size number

The number of samples to generate (must be a positive integer).

Source:
Returns:

An array of randomly selected elements from an array.

Type
array

randomUnitVector() → {Vector}

Generate a random unit vector.

Source:
Returns:

A Vector with a magnitude of 1 and a random angle between 0 and TWO_PI.

Type
Vector

randomVectorInAABB(box) → {Vector}

Generate a random vector within the bounds of a given AABB.

Parameters:
Name Type Description
box AABB

The box to generate the vector within.

Source:
Returns:

A Vector within the AABB.

Type
Vector

randomVectorInCircle(circle) → {Vector}

Generate a random Vector within a given Circle.

Parameters:
Name Type Description
circle Circle

The circle to generate the Vector within.

Source:
Returns:

A Vector within the Circle.

Type
Vector

randomWeighted(choices) → {function|number|string}

Selects an option probabalistically from a set of weighted choices.

Parameters:
Name Type Description
choices Array.<Object>

An array of objects with option and weight properties.

Properties
Name Type Description
option function | number | string

The outcome of the choice.

weight number

The weight of the choice. Higher weights (relative to the other choices) increase the likelihood of selection.

Source:
Returns:

The selected option.

Type
function | number | string