Constructor
(abstract) new PRNG(seedopt)
Abstract base class representing a Psuedo Random Number Generator.
This class is intended to be extended by specific implementations such as LCG, Mulberry32 or XORShift32.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
seed | number | <optional> | Date.now() | The initial seed value for the PRNG. |
Classes
- PRNG
Abstract base class representing a Psuedo Random Number Generator.
Methods
maxValue() → {number}
Returns the maximum possible value that the PRNG can generate.
- Must be implemented by subclasses.
- Type
- Error
- The maximum value of the PRNG.
- Type:
- number
next() → {number}
Generates the next psuedo-random number.
- Must be implemented by subclasses.
- Type
- Error
- The next psuedo-random number.
- Type:
- number
randomBipolarFloat() → {number}
Generate a random float in the range [-1, 1).
- A number between -1 (inclusive) and 1 (exclusive).
- Type:
- number
randomChance(chanceopt) → {boolean}
Returns a boolean based on a specified probability.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chance | number | <optional> | 0.5 | The probability of returning true (between 0 and 1). |
- True if the random float is less than the chance, otherwise false.
- Type:
- boolean
randomElement(array) → {*}
Select a random element from an array.
Name | Type | Description |
---|---|---|
array | array | The array from which to select an element. |
- A randomly selected element from the array.
- Type:
- *
randomFloat() → {number}
Generate a random float in the range [0, 1).
- A number between 0 (inclusive) and 1 (exclusive).
- Type:
- number
randomInteger(min, max) → {number}
Generate a random integer from a specified range of values.
Name | Type | Description |
---|---|---|
min | number | The minimum integer value (inclusive). |
max | number | The maximum integer value (exclusive). |
- A random integer between min (inclusive) and max (exclusive).
- Type:
- number
randomWeighted(choices) → {function|number|string}
Selects an option probabalistically from a set of weighted choices.
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
choices | Array.<Object> | An array of objects with Properties
|
- The selected option.
- Type:
- function |
number | string