Constructor
new RandomGenerator(seedopt)
Create a random number generator with the seed passed in
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
seed | number | <optional> | 123456789 | Starting seed or engine default 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
angle() → {number}
Returns a random angle between -PI and PI
- Source
Returns:
- Type:
- number
bool(chanceopt) → {boolean}
Randomly returns true or false given the chance of true passed in
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chance | number | <optional> | 0.5 |
- Source
Returns:
- Type:
- boolean
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
floatSign(valueAopt, valueBopt) → {number}
Returns a seeded random value between the two values passed in with a random sign
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
mutateColor(color, amountopt, alphaAmountopt) → {Color}
Returns a new color that has each component randomly adjusted
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
color | Color | |||
amount | number | <optional> | 0.05 | |
alphaAmount | number | <optional> | 0 |
- Source
Returns:
- Type:
- Color
randColor(colorAopt, colorBopt, linearopt) → {Color}
Returns a random color between the two passed in colors, combine components if linear
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
colorA | Color | <optional> | (1,1,1,1) | |
colorB | Color | <optional> | (0,0,0,1) | |
linear | boolean | <optional> | false |
- Source
Returns:
- Type:
- Color
sign() → {number}
Randomly returns either -1 or 1 deterministically
- Source
Returns:
- Type:
- number
vec2(valueA, valueBopt) → {Vector2}
Returns a seeded vec2 with size between the two values passed in
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
valueA | number | 1 | ||
valueB | number | <optional> | 0 |
- Source
Returns:
- Type:
- Vector2