Constructor
new RandomGenerator(seed)
Create a random number generator with the seed passed in
Parameters:
Name | Type | Description |
---|---|---|
seed | Number | Starting seed |
- Source
Example
let r = new RandomGenerator(123); // random number generator with seed 123
let a = r.float(); // random value between 0 and 1
let b = r.int(10); // random integer between 0 and 9
r.seed = 123; // reset the seed
let c = r.float(); // the same value as a
Members
seed
PropertiesType | Description |
---|---|
Number | random seed |
- Source
Methods
float(valueAopt, valueBopt) → {Number}
Returns a seeded random value between the two values passed in
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
valueA | Number | <optional> | 1 | |
valueB | Number | <optional> | 0 |
- Source
Returns:
- Type:
- Number
int(valueA, valueBopt) → {Number}
Returns a floored seeded random value the two values passed in
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
valueA | Number | |||
valueB | Number | <optional> | 0 |
- Source
Returns:
- Type:
- Number
sign() → {Number}
Randomly returns either -1 or 1 deterministically
- Source
Returns:
- Type:
- Number