Class: RandomSeed
This is a util that implements a liner congruential generator to generate random number.
See
https://en.wikipedia.org/wiki/Linear_congruential_generator (opens in a new tab)
Usage
const seed = new RandomSeed(1234);
const value = seed.value();
const range = seed.range(1, 10);
const fromArray = seed.fromArray(['a', 'b', 'c']);
console.log(value, range, fromArray);
Table of contents
Constructors
Methods
Constructors
constructor
new RandomSeed(seed?
): RandomSeed
Parameters
Name | Type | Description |
---|---|---|
seed? | number | optional seed to use, if not provided a fixed value will be used. |
Returns
Methods
fromArray
fromArray<T
>(array
): T
Type parameters
Name | Description |
---|---|
T | the identity type, given an array of strings for example, the returned random item will be string |
Parameters
Name | Type |
---|---|
array | T [] |
Returns
T
a random item from the given array
int
int(min?
, max?
): number
Parameters
Name | Type | Default value | Description |
---|---|---|---|
min | number | 0 | min value |
max | number | 2147483647 | max value |
Returns
number
- a random number based on the current seed
reset
reset(): void
resets the current seed to the origin seed
Returns
void