new PRNG(optionsopt)
Creates an instance of PRNG.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
{} | The configuration options for the PRNG. Properties
|
Classes
Methods
randomBipolarFloat() → {number}
Generate a random float in the range [-1, 1).
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). |
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. |
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. |
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. |
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). |
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). |
Returns:
An array of randomly selected elements from an array.
- Type
- array
randomUnitVector() → {Vector}
Generate a random unit vector.
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. |
Returns:
- Type
- Vector
randomVectorInCircle(circle) → {Vector}
Parameters:
Name | Type | Description |
---|---|---|
circle |
Circle | The circle to generate the Vector within. |
Returns:
- 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 Properties
|
Returns:
The selected option.
- Type
- function | number | string