Constructor
new SeededRandom(seed)
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
seed |
String | Number |
null
|
Methods
(static) fromState(state) → {SeededRandom}
- Source:
Create a new instance from an exported state
Parameters:
Name | Type | Description |
---|---|---|
state |
Array |
Returns:
- Type
- SeededRandom
bool() → {Boolean}
- Source:
Get a boolean
Returns:
- Type
- Boolean
chance() → {Boolean}
- Source:
Get a boolean with a defined chance
Returns:
- Type
- Boolean
entry(arr, remove) → {mixed}
- Source:
Get a random entry of an array
Parameters:
Name | Type | Default | Description |
---|---|---|---|
arr |
Array | ||
remove |
Boolean |
false
|
remove the entry from the array |
Returns:
an entry of the array
- Type
- mixed
exportState() → {Array}
- Source:
- See:
Export the state of the internal alea instance
Returns:
- Type
- Array
float(min, max) → {Number}
- Source:
Get a decimal number between min and max
Parameters:
Name | Type | Description |
---|---|---|
min |
Number | |
max |
Number |
Returns:
- Type
- Number
getSimplex() → {Simplex}
Get a simplex noise instance
Returns:
- Type
- Simplex
importState(state) → {Alea}
- Source:
- See:
Import the state of the internal alea instance
Parameters:
Name | Type | Description |
---|---|---|
state |
Array |
Returns:
the alea instance
- Type
- Alea
int(min, max) → {Number}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
min |
Number | |
max |
Number |
Returns:
an integer
- Type
- Number
weighted(map) → {String}
- Source:
Return a key from a weighted map, this is useful for dynamic loot tables, the weights do not need to add up to 100%. The following example demonstrates how the propability of the items is calculated by the weight
Example
let r = new SeededRandom("seed");
let loot = {
stone_sword: 10,
diamond_axe: 5,
wooden_sword: 15
}
let item = r.weighted(loot);
// "wooden_sword" with a propability of 50%
// "diamond_axe" with a propability of 16.6%
// "stone_sword" with a propability of 33.3%
Parameters:
Name | Type | Description |
---|---|---|
map |
Object | the weight map |
Returns:
a key of the map
- Type
- String