248 lines
8.3 KiB
Plaintext
248 lines
8.3 KiB
Plaintext
|
|
{{alias}}( [options] )
|
|
Returns a readable stream for generating uniformly distributed pseudorandom
|
|
numbers between 0 and 1.
|
|
|
|
In addition to standard readable stream events, the returned stream emits a
|
|
'state' event after internally generating `siter` pseudorandom numbers,
|
|
which is useful when wanting to deterministically capture a stream's
|
|
underlying PRNG state.
|
|
|
|
The default underlying pseudorandom number generator (PRNG) *may* change in
|
|
the future. If exact reproducibility is required, either explicitly specify
|
|
a PRNG via the `name` option or use an underlying PRNG directly.
|
|
|
|
Parameters
|
|
----------
|
|
options: Object (optional)
|
|
Options.
|
|
|
|
options.objectMode: boolean (optional)
|
|
Specifies whether a stream should operate in "objectMode". Default:
|
|
false.
|
|
|
|
options.encoding: string|null (optional)
|
|
Specifies how Buffer objects should be decoded to strings. Default:
|
|
null.
|
|
|
|
options.highWaterMark: integer (optional)
|
|
Specifies the maximum number of bytes to store in an internal buffer
|
|
before ceasing to generate additional pseudorandom numbers.
|
|
|
|
options.sep: string (optional)
|
|
Separator used to join streamed data. This option is only applicable
|
|
when a stream is not in "objectMode". Default: '\n'.
|
|
|
|
options.iter: integer (optional)
|
|
Number of iterations.
|
|
|
|
options.name: string (optional)
|
|
Name of a supported pseudorandom number generator (PRNG), which will
|
|
serve as the underlying source of pseudorandom numbers. The following
|
|
PRNGs are supported:
|
|
|
|
- mt19937: 32-bit Mersenne Twister.
|
|
- minstd: linear congruential PRNG based on Park and Miller.
|
|
- minstd-shuffle: linear congruential PRNG whose output is shuffled.
|
|
|
|
Default: 'mt19937'.
|
|
|
|
options.seed: any (optional)
|
|
Pseudorandom number generator seed. Valid seed values vary according to
|
|
the underlying PRNG.
|
|
|
|
options.state: any (optional)
|
|
Pseudorandom number generator state. Valid state values vary according
|
|
to the underling PRNG. If provided, the `seed` option is ignored.
|
|
|
|
options.copy: boolean (optional)
|
|
Boolean indicating whether to copy a provided pseudorandom number
|
|
generator state. Setting this option to `false` allows sharing state
|
|
between two or more pseudorandom number generators. Setting this option
|
|
to `true` ensures that a returned iterator has exclusive control over
|
|
its internal state. Default: true.
|
|
|
|
options.siter: integer (optional)
|
|
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
|
|
Returns
|
|
-------
|
|
stream: ReadableStream
|
|
Readable stream.
|
|
|
|
stream.PRNG: Function
|
|
Underlying pseudorandom number generator.
|
|
|
|
stream.seed: any
|
|
Pseudorandom number generator seed.
|
|
|
|
stream.seedLength: integer
|
|
Length of generator seed.
|
|
|
|
stream.state: any
|
|
Generator state.
|
|
|
|
stream.stateLength: integer
|
|
Length of generator state.
|
|
|
|
stream.byteLength: integer
|
|
Size (in bytes) of generator state.
|
|
|
|
Examples
|
|
--------
|
|
> function fcn( chunk ) { console.log( chunk.toString() ); };
|
|
> var opts = { 'iter': 10 };
|
|
> var s = {{alias}}( opts );
|
|
> var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn );
|
|
> s.pipe( o );
|
|
|
|
|
|
{{alias}}.factory( [options] )
|
|
Returns a function for creating readable streams which generate uniformly
|
|
distributed pseudorandom numbers between 0 and 1.
|
|
|
|
Parameters
|
|
----------
|
|
options.objectMode: boolean (optional)
|
|
Specifies whether a stream should operate in "objectMode". Default:
|
|
false.
|
|
|
|
options.encoding: string|null (optional)
|
|
Specifies how Buffer objects should be decoded to strings. Default:
|
|
null.
|
|
|
|
options.highWaterMark: integer (optional)
|
|
Specifies the maximum number of bytes to store in an internal buffer
|
|
before ceasing to generate additional pseudorandom numbers.
|
|
|
|
options.sep: string (optional)
|
|
Separator used to join streamed data. This option is only applicable
|
|
when a stream is not in "objectMode". Default: '\n'.
|
|
|
|
options.iter: integer (optional)
|
|
Number of iterations.
|
|
|
|
options.name: string (optional)
|
|
Name of a supported pseudorandom number generator (PRNG), which will
|
|
serve as the underlying source of pseudorandom numbers. The following
|
|
PRNGs are supported:
|
|
|
|
- mt19937: 32-bit Mersenne Twister.
|
|
- minstd: linear congruential PRNG based on Park and Miller.
|
|
- minstd-shuffle: linear congruential PRNG whose output is shuffled.
|
|
|
|
Default: 'mt19937'.
|
|
|
|
options.seed: any (optional)
|
|
Pseudorandom number generator seed. Valid seed values vary according to
|
|
the underlying PRNG.
|
|
|
|
options.state: any (optional)
|
|
Pseudorandom number generator state. Valid state values vary according
|
|
to the underling PRNG. If provided, the `seed` option is ignored.
|
|
|
|
options.copy: boolean (optional)
|
|
Boolean indicating whether to copy a provided pseudorandom number
|
|
generator state. Setting this option to `false` allows sharing state
|
|
between two or more pseudorandom number generators. Setting this option
|
|
to `true` ensures that a returned iterator has exclusive control over
|
|
its internal state. Default: true.
|
|
|
|
options.siter: integer (optional)
|
|
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
|
|
Returns
|
|
-------
|
|
fcn: Function
|
|
Function for creating readable streams.
|
|
|
|
Examples
|
|
--------
|
|
> var opts = { 'objectMode': true, 'highWaterMark': 64 };
|
|
> var createStream = {{alias}}.factory( opts );
|
|
|
|
|
|
{{alias}}.objectMode( [options] )
|
|
Returns an "objectMode" readable stream for generating uniformly distributed
|
|
pseudorandom numbers between 0 and 1.
|
|
|
|
Parameters
|
|
----------
|
|
options: Object (optional)
|
|
Options.
|
|
|
|
options.encoding: string|null (optional)
|
|
Specifies how Buffer objects should be decoded to strings. Default:
|
|
null.
|
|
|
|
options.highWaterMark: integer (optional)
|
|
Specifies the maximum number of objects to store in an internal buffer
|
|
before ceasing to generate additional pseudorandom numbers.
|
|
|
|
options.iter: integer (optional)
|
|
Number of iterations.
|
|
|
|
options.name: string (optional)
|
|
Name of a supported pseudorandom number generator (PRNG), which will
|
|
serve as the underlying source of pseudorandom numbers. The following
|
|
PRNGs are supported:
|
|
|
|
- mt19937: 32-bit Mersenne Twister.
|
|
- minstd: linear congruential PRNG based on Park and Miller.
|
|
- minstd-shuffle: linear congruential PRNG whose output is shuffled.
|
|
|
|
Default: 'mt19937'.
|
|
|
|
options.seed: any (optional)
|
|
Pseudorandom number generator seed. Valid seed values vary according to
|
|
the underlying PRNG.
|
|
|
|
options.state: any (optional)
|
|
Pseudorandom number generator state. Valid state values vary according
|
|
to the underling PRNG. If provided, the `seed` option is ignored.
|
|
|
|
options.copy: boolean (optional)
|
|
Boolean indicating whether to copy a provided pseudorandom number
|
|
generator state. Setting this option to `false` allows sharing state
|
|
between two or more pseudorandom number generators. Setting this option
|
|
to `true` ensures that a returned iterator has exclusive control over
|
|
its internal state. Default: true.
|
|
|
|
options.siter: integer (optional)
|
|
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
|
|
Returns
|
|
-------
|
|
stream: ReadableStream
|
|
Readable stream operating in "objectMode".
|
|
|
|
stream.PRNG: Function
|
|
Underlying pseudorandom number generator.
|
|
|
|
stream.seed: any
|
|
Pseudorandom number generator seed.
|
|
|
|
stream.seedLength: integer
|
|
Length of generator seed.
|
|
|
|
stream.state: any
|
|
Generator state.
|
|
|
|
stream.stateLength: integer
|
|
Length of generator state.
|
|
|
|
stream.byteLength: integer
|
|
Size (in bytes) of generator state.
|
|
|
|
Examples
|
|
--------
|
|
> function fcn( v ) { console.log( v ); };
|
|
> var opts = { 'iter': 10 };
|
|
> var s = {{alias}}.objectMode( opts );
|
|
> var o = {{alias:@stdlib/streams/node/inspect-sink}}.objectMode( fcn );
|
|
> s.pipe( o );
|
|
|
|
See Also
|
|
--------
|
|
|