Constructor
new Generator(bitGeneratoropt)
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
bitGenerator |
BitGenerator |
<optional> |
The underlying bit generator. A randomly seeded xoshiro128** is used when omitted. |
- Source:
Example
const rng = createGenerator(42)
rng.normal(0, 1, 5)
rng.integers(0, 10, [2, 3])
const saved = rng.getState()
const a = rng.random()
rng.setState(saved)
rng.random() === a // true
Classes
Members
bitGenerator :BitGenerator
The underlying bit generator.
Type:
- BitGenerator
- Source:
Methods
clone() → {Generator}
Returns an independent copy positioned at the same point of the stream.
- Source:
Returns:
- Type
- Generator
getState() → {Object}
Returns a JSON serialisable snapshot of the generator state.
- Source:
Returns:
- Type
- Object
run(fn) → {*}
Runs fn with this generator installed as the source of every module level sampling
function, so third party code built on the global functions uses this stream.
Parameters:
| Name | Type | Description |
|---|---|---|
fn |
function |
- Source:
Returns:
The value returned by fn.
- Type
- *
setState(state) → {this}
Restores a snapshot returned by Generator#getState.
Parameters:
| Name | Type | Description |
|---|---|---|
state |
Object |
- Source:
Returns:
- Type
- this
spawn(n) → {Array.<Generator>}
Creates n child generators with statistically independent streams, seeded from this
generator (deterministic when this generator is seeded). Useful for parallel simulations.
Parameters:
| Name | Type | Description |
|---|---|---|
n |
number | Number of children. |
- Source:
Returns:
- Type
- Array.<Generator>