@stdlib/random-streams-normal 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CITATION.cff +30 -0
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +31 -87
- package/dist/index.d.ts +3 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/lib/factory.js +12 -3
- package/lib/index.js +4 -4
- package/lib/main.js +5 -4
- package/lib/object_mode.js +4 -3
- package/lib/validate.js +9 -8
- package/package.json +26 -52
- package/bin/cli +0 -194
- package/docs/repl.txt +0 -262
- package/docs/types/test.ts +0 -135
- package/docs/usage.txt +0 -15
- package/etc/cli_opts.json +0 -24
package/docs/repl.txt
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( μ, σ[, options] )
|
|
3
|
-
Returns a readable stream for generating pseudorandom numbers drawn from a
|
|
4
|
-
normal distribution.
|
|
5
|
-
|
|
6
|
-
In addition to standard readable stream events, the returned stream emits a
|
|
7
|
-
'state' event after internally generating `siter` pseudorandom numbers,
|
|
8
|
-
which is useful when wanting to deterministically capture a stream's
|
|
9
|
-
underlying PRNG state.
|
|
10
|
-
|
|
11
|
-
Parameters
|
|
12
|
-
----------
|
|
13
|
-
μ: number
|
|
14
|
-
Mean.
|
|
15
|
-
|
|
16
|
-
σ: number
|
|
17
|
-
Standard deviation.
|
|
18
|
-
|
|
19
|
-
options: Object (optional)
|
|
20
|
-
Options.
|
|
21
|
-
|
|
22
|
-
options.objectMode: boolean (optional)
|
|
23
|
-
Specifies whether a stream should operate in "objectMode". Default:
|
|
24
|
-
false.
|
|
25
|
-
|
|
26
|
-
options.encoding: string|null (optional)
|
|
27
|
-
Specifies how Buffer objects should be decoded to strings. Default:
|
|
28
|
-
null.
|
|
29
|
-
|
|
30
|
-
options.highWaterMark: integer (optional)
|
|
31
|
-
Specifies the maximum number of bytes to store in an internal buffer
|
|
32
|
-
before ceasing to generate additional pseudorandom numbers.
|
|
33
|
-
|
|
34
|
-
options.sep: string (optional)
|
|
35
|
-
Separator used to join streamed data. This option is only applicable
|
|
36
|
-
when a stream is not in "objectMode". Default: '\n'.
|
|
37
|
-
|
|
38
|
-
options.iter: integer (optional)
|
|
39
|
-
Number of iterations.
|
|
40
|
-
|
|
41
|
-
options.prng: Function (optional)
|
|
42
|
-
Pseudorandom number generator (PRNG) for generating uniformly
|
|
43
|
-
distributed pseudorandom numbers on the interval `[0,1)`. If provided,
|
|
44
|
-
the `state` and `seed` options are ignored. In order to seed the
|
|
45
|
-
returned iterator, one must seed the provided `prng` (assuming the
|
|
46
|
-
provided `prng` is seedable).
|
|
47
|
-
|
|
48
|
-
options.seed: integer|ArrayLikeObject<integer> (optional)
|
|
49
|
-
Pseudorandom number generator seed. The seed may be either a positive
|
|
50
|
-
unsigned 32-bit integer or, for arbitrary length seeds, an array-like
|
|
51
|
-
object containing unsigned 32-bit integers.
|
|
52
|
-
|
|
53
|
-
options.state: Uint32Array (optional)
|
|
54
|
-
Pseudorandom number generator state. If provided, the `seed` option is
|
|
55
|
-
ignored.
|
|
56
|
-
|
|
57
|
-
options.copy: boolean (optional)
|
|
58
|
-
Boolean indicating whether to copy a provided pseudorandom number
|
|
59
|
-
generator state. Setting this option to `false` allows sharing state
|
|
60
|
-
between two or more pseudorandom number generators. Setting this option
|
|
61
|
-
to `true` ensures that a returned iterator has exclusive control over
|
|
62
|
-
its internal state. Default: true.
|
|
63
|
-
|
|
64
|
-
options.siter: integer (optional)
|
|
65
|
-
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
66
|
-
|
|
67
|
-
Returns
|
|
68
|
-
-------
|
|
69
|
-
stream: ReadableStream
|
|
70
|
-
Readable stream.
|
|
71
|
-
|
|
72
|
-
stream.PRNG: Function
|
|
73
|
-
Underlying pseudorandom number generator.
|
|
74
|
-
|
|
75
|
-
stream.seed: Uint32Array|null
|
|
76
|
-
Pseudorandom number generator seed.
|
|
77
|
-
|
|
78
|
-
stream.seedLength: integer|null
|
|
79
|
-
Length of generator seed.
|
|
80
|
-
|
|
81
|
-
stream.state: Uint32Array|null
|
|
82
|
-
Generator state.
|
|
83
|
-
|
|
84
|
-
stream.stateLength: integer|null
|
|
85
|
-
Length of generator state.
|
|
86
|
-
|
|
87
|
-
stream.byteLength: integer|null
|
|
88
|
-
Size (in bytes) of generator state.
|
|
89
|
-
|
|
90
|
-
Examples
|
|
91
|
-
--------
|
|
92
|
-
> function fcn( chunk ) { console.log( chunk.toString() ); };
|
|
93
|
-
> var opts = { 'iter': 10 };
|
|
94
|
-
> var s = {{alias}}( 2.0, 5.0, opts );
|
|
95
|
-
> var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn );
|
|
96
|
-
> s.pipe( o );
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{{alias}}.factory( [μ, σ, ][options] )
|
|
100
|
-
Returns a function for creating readable streams which generate pseudorandom
|
|
101
|
-
numbers drawn from a normal distribution.
|
|
102
|
-
|
|
103
|
-
If provided distribution parameters, the returned function returns readable
|
|
104
|
-
streams which generate pseudorandom numbers drawn from the specified
|
|
105
|
-
distribution.
|
|
106
|
-
|
|
107
|
-
If not provided distribution parameters, the returned function requires that
|
|
108
|
-
distribution parameters be provided at each invocation.
|
|
109
|
-
|
|
110
|
-
Parameters
|
|
111
|
-
----------
|
|
112
|
-
μ: number (optional)
|
|
113
|
-
Mean.
|
|
114
|
-
|
|
115
|
-
σ: number (optional)
|
|
116
|
-
Standard deviation.
|
|
117
|
-
|
|
118
|
-
options: Object (optional)
|
|
119
|
-
Options.
|
|
120
|
-
|
|
121
|
-
options.objectMode: boolean (optional)
|
|
122
|
-
Specifies whether a stream should operate in "objectMode". Default:
|
|
123
|
-
false.
|
|
124
|
-
|
|
125
|
-
options.encoding: string|null (optional)
|
|
126
|
-
Specifies how Buffer objects should be decoded to strings. Default:
|
|
127
|
-
null.
|
|
128
|
-
|
|
129
|
-
options.highWaterMark: integer (optional)
|
|
130
|
-
Specifies the maximum number of bytes to store in an internal buffer
|
|
131
|
-
before ceasing to generate additional pseudorandom numbers.
|
|
132
|
-
|
|
133
|
-
options.sep: string (optional)
|
|
134
|
-
Separator used to join streamed data. This option is only applicable
|
|
135
|
-
when a stream is not in "objectMode". Default: '\n'.
|
|
136
|
-
|
|
137
|
-
options.iter: integer (optional)
|
|
138
|
-
Number of iterations.
|
|
139
|
-
|
|
140
|
-
options.prng: Function (optional)
|
|
141
|
-
Pseudorandom number generator (PRNG) for generating uniformly
|
|
142
|
-
distributed pseudorandom numbers on the interval `[0,1)`. If provided,
|
|
143
|
-
the `state` and `seed` options are ignored. In order to seed the
|
|
144
|
-
returned iterator, one must seed the provided `prng` (assuming the
|
|
145
|
-
provided `prng` is seedable).
|
|
146
|
-
|
|
147
|
-
options.seed: integer|ArrayLikeObject<integer> (optional)
|
|
148
|
-
Pseudorandom number generator seed. The seed may be either a positive
|
|
149
|
-
unsigned 32-bit integer or, for arbitrary length seeds, an array-like
|
|
150
|
-
object containing unsigned 32-bit integers.
|
|
151
|
-
|
|
152
|
-
options.state: Uint32Array (optional)
|
|
153
|
-
Pseudorandom number generator state. If provided, the `seed` option is
|
|
154
|
-
ignored.
|
|
155
|
-
|
|
156
|
-
options.copy: boolean (optional)
|
|
157
|
-
Boolean indicating whether to copy a provided pseudorandom number
|
|
158
|
-
generator state. Setting this option to `false` allows sharing state
|
|
159
|
-
between two or more pseudorandom number generators. Setting this option
|
|
160
|
-
to `true` ensures that a returned iterator has exclusive control over
|
|
161
|
-
its internal state. Default: true.
|
|
162
|
-
|
|
163
|
-
options.siter: integer (optional)
|
|
164
|
-
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
165
|
-
|
|
166
|
-
Returns
|
|
167
|
-
-------
|
|
168
|
-
fcn: Function
|
|
169
|
-
Function for creating readable streams.
|
|
170
|
-
|
|
171
|
-
Examples
|
|
172
|
-
--------
|
|
173
|
-
> var opts = { 'objectMode': true, 'highWaterMark': 64 };
|
|
174
|
-
> var createStream = {{alias}}.factory( opts );
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
{{alias}}.objectMode( μ, σ[, options] )
|
|
178
|
-
Returns an "objectMode" readable stream for generating pseudorandom numbers
|
|
179
|
-
drawn from a normal distribution.
|
|
180
|
-
|
|
181
|
-
Parameters
|
|
182
|
-
----------
|
|
183
|
-
μ: number
|
|
184
|
-
Mean.
|
|
185
|
-
|
|
186
|
-
σ: number
|
|
187
|
-
Standard deviation.
|
|
188
|
-
|
|
189
|
-
options: Object (optional)
|
|
190
|
-
Options.
|
|
191
|
-
|
|
192
|
-
options.encoding: string|null (optional)
|
|
193
|
-
Specifies how Buffer objects should be decoded to strings. Default:
|
|
194
|
-
null.
|
|
195
|
-
|
|
196
|
-
options.highWaterMark: integer (optional)
|
|
197
|
-
Specifies the maximum number of objects to store in an internal buffer
|
|
198
|
-
before ceasing to generate additional pseudorandom numbers.
|
|
199
|
-
|
|
200
|
-
options.iter: integer (optional)
|
|
201
|
-
Number of iterations.
|
|
202
|
-
|
|
203
|
-
options.prng: Function (optional)
|
|
204
|
-
Pseudorandom number generator (PRNG) for generating uniformly
|
|
205
|
-
distributed pseudorandom numbers on the interval `[0,1)`. If provided,
|
|
206
|
-
the `state` and `seed` options are ignored. In order to seed the
|
|
207
|
-
returned iterator, one must seed the provided `prng` (assuming the
|
|
208
|
-
provided `prng` is seedable).
|
|
209
|
-
|
|
210
|
-
options.seed: integer|ArrayLikeObject<integer> (optional)
|
|
211
|
-
Pseudorandom number generator seed. The seed may be either a positive
|
|
212
|
-
unsigned 32-bit integer or, for arbitrary length seeds, an array-like
|
|
213
|
-
object containing unsigned 32-bit integers.
|
|
214
|
-
|
|
215
|
-
options.state: Uint32Array (optional)
|
|
216
|
-
Pseudorandom number generator state. If provided, the `seed` option is
|
|
217
|
-
ignored.
|
|
218
|
-
|
|
219
|
-
options.copy: boolean (optional)
|
|
220
|
-
Boolean indicating whether to copy a provided pseudorandom number
|
|
221
|
-
generator state. Setting this option to `false` allows sharing state
|
|
222
|
-
between two or more pseudorandom number generators. Setting this option
|
|
223
|
-
to `true` ensures that a returned iterator has exclusive control over
|
|
224
|
-
its internal state. Default: true.
|
|
225
|
-
|
|
226
|
-
options.siter: integer (optional)
|
|
227
|
-
Number of iterations after which to emit the PRNG state. Default: 1e308.
|
|
228
|
-
|
|
229
|
-
Returns
|
|
230
|
-
-------
|
|
231
|
-
stream: ReadableStream
|
|
232
|
-
Readable stream operating in "objectMode".
|
|
233
|
-
|
|
234
|
-
stream.PRNG: Function
|
|
235
|
-
Underlying pseudorandom number generator.
|
|
236
|
-
|
|
237
|
-
stream.seed: Uint32Array|null
|
|
238
|
-
Pseudorandom number generator seed.
|
|
239
|
-
|
|
240
|
-
stream.seedLength: integer|null
|
|
241
|
-
Length of generator seed.
|
|
242
|
-
|
|
243
|
-
stream.state: Uint32Array|null
|
|
244
|
-
Generator state.
|
|
245
|
-
|
|
246
|
-
stream.stateLength: integer|null
|
|
247
|
-
Length of generator state.
|
|
248
|
-
|
|
249
|
-
stream.byteLength: integer|null
|
|
250
|
-
Size (in bytes) of generator state.
|
|
251
|
-
|
|
252
|
-
Examples
|
|
253
|
-
--------
|
|
254
|
-
> function fcn( v ) { console.log( v ); };
|
|
255
|
-
> var opts = { 'iter': 10 };
|
|
256
|
-
> var s = {{alias}}.objectMode( 2.0, 5.0, opts );
|
|
257
|
-
> var o = {{alias:@stdlib/streams/node/inspect-sink}}.objectMode( fcn );
|
|
258
|
-
> s.pipe( o );
|
|
259
|
-
|
|
260
|
-
See Also
|
|
261
|
-
--------
|
|
262
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import RandomStream = require( './index' );
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// TESTS //
|
|
23
|
-
|
|
24
|
-
// The constructor returns a stream...
|
|
25
|
-
{
|
|
26
|
-
// tslint:disable: no-unused-expression
|
|
27
|
-
new RandomStream( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
28
|
-
new RandomStream( 2.0, 5.0, {} ); // $ExpectType RandomStream
|
|
29
|
-
new RandomStream( 2.0, 5.0, { 'iter': 10 } ); // $ExpectType RandomStream
|
|
30
|
-
|
|
31
|
-
// tslint:enable: no-unused-expression
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// The constructor is callable...
|
|
35
|
-
{
|
|
36
|
-
const randomStream = RandomStream;
|
|
37
|
-
|
|
38
|
-
randomStream( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
39
|
-
randomStream( 2.0, 5.0, {} ); // $ExpectType RandomStream
|
|
40
|
-
randomStream( 2.0, 5.0, { 'iter': 10 } ); // $ExpectType RandomStream
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// The constructor has an `objectMode` method which returns a stream...
|
|
44
|
-
{
|
|
45
|
-
RandomStream.objectMode( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
46
|
-
RandomStream.objectMode( 2.0, 5.0, {} ); // $ExpectType RandomStream
|
|
47
|
-
RandomStream.objectMode( 2.0, 5.0, { 'iter': 10 } ); // $ExpectType RandomStream
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// The constructor has a `factory` method which returns a function for creating streams...
|
|
51
|
-
{
|
|
52
|
-
let f = RandomStream.factory( 2.0, 5.0 );
|
|
53
|
-
f(); // $ExpectType RandomStream
|
|
54
|
-
f(); // $ExpectType RandomStream
|
|
55
|
-
f(); // $ExpectType RandomStream
|
|
56
|
-
|
|
57
|
-
f = RandomStream.factory( 2.0, 5.0, {} );
|
|
58
|
-
f(); // $ExpectType RandomStream
|
|
59
|
-
f(); // $ExpectType RandomStream
|
|
60
|
-
f(); // $ExpectType RandomStream
|
|
61
|
-
|
|
62
|
-
f = RandomStream.factory( 2.0, 5.0, { 'iter': 10 } );
|
|
63
|
-
f(); // $ExpectType RandomStream
|
|
64
|
-
f(); // $ExpectType RandomStream
|
|
65
|
-
f(); // $ExpectType RandomStream
|
|
66
|
-
|
|
67
|
-
f = RandomStream.factory();
|
|
68
|
-
f( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
69
|
-
f( 1.0, 2.0 ); // $ExpectType RandomStream
|
|
70
|
-
f( 3.0, 1.0 ); // $ExpectType RandomStream
|
|
71
|
-
|
|
72
|
-
f = RandomStream.factory( {} );
|
|
73
|
-
f( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
74
|
-
f( 1.0, 2.0 ); // $ExpectType RandomStream
|
|
75
|
-
f( 3.0, 1.0 ); // $ExpectType RandomStream
|
|
76
|
-
|
|
77
|
-
f = RandomStream.factory( { 'iter': 10 } );
|
|
78
|
-
f( 2.0, 5.0 ); // $ExpectType RandomStream
|
|
79
|
-
f( 1.0, 2.0 ); // $ExpectType RandomStream
|
|
80
|
-
f( 3.0, 1.0 ); // $ExpectType RandomStream
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// The compiler throws an error if the constructor is provided invalid input arguments...
|
|
84
|
-
{
|
|
85
|
-
const s1 = new RandomStream( '2.0', 5.0 ); // $ExpectError
|
|
86
|
-
const s2 = new RandomStream( 2.0, '5.0' ); // $ExpectError
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// The compiler throws an error if the `objectMode` method is provided invalid input arguments...
|
|
90
|
-
{
|
|
91
|
-
RandomStream.objectMode( '2.0', 5.0 ); // $ExpectError
|
|
92
|
-
RandomStream.objectMode( 2.0, '5.0' ); // $ExpectError
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// The compiler throws an error if the `factory` method is provided invalid input arguments...
|
|
96
|
-
{
|
|
97
|
-
RandomStream.factory( '2.0', 5.0 ); // $ExpectError
|
|
98
|
-
RandomStream.factory( '2.0', 5.0, {} ); // $ExpectError
|
|
99
|
-
|
|
100
|
-
RandomStream.factory( 2.0, '5.0' ); // $ExpectError
|
|
101
|
-
RandomStream.factory( 2.0, '5.0', {} ); // $ExpectError
|
|
102
|
-
|
|
103
|
-
RandomStream.factory( 2.0, 5.0, null ); // $ExpectError
|
|
104
|
-
RandomStream.factory( 2.0, 5.0, { 'iter': 'beep' } ); // $ExpectError
|
|
105
|
-
|
|
106
|
-
RandomStream.factory( null ); // $ExpectError
|
|
107
|
-
RandomStream.factory( { 'iter': 'beep' } ); // $ExpectError
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// The compiler throws an error if the function returned by the `factory` method is provided invalid input arguments...
|
|
111
|
-
{
|
|
112
|
-
let f = RandomStream.factory();
|
|
113
|
-
f( '2.0', 5.0 ); // $ExpectError
|
|
114
|
-
f( 2.0, '5.0' ); // $ExpectError
|
|
115
|
-
|
|
116
|
-
f = RandomStream.factory( {} );
|
|
117
|
-
f( '2.0', 5.0 ); // $ExpectError
|
|
118
|
-
f( 2.0, '5.0' ); // $ExpectError
|
|
119
|
-
|
|
120
|
-
f = RandomStream.factory( { 'iter': 10 } );
|
|
121
|
-
f( '2.0', 5.0 ); // $ExpectError
|
|
122
|
-
f( 2.0, '5.0' ); // $ExpectError
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// The compiler throws an error if the constructor is provided insufficient arguments...
|
|
126
|
-
{
|
|
127
|
-
const s1 = new RandomStream(); // $ExpectError
|
|
128
|
-
const s2 = new RandomStream( 2.0 ); // $ExpectError
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// The compiler throws an error if the `objectMode` method is provided insufficient arguments...
|
|
132
|
-
{
|
|
133
|
-
RandomStream.objectMode(); // $ExpectError
|
|
134
|
-
RandomStream.objectMode( 2.0 ); // $ExpectError
|
|
135
|
-
}
|
package/docs/usage.txt
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Usage: random-normal [options] <mu> <sigma>
|
|
3
|
-
|
|
4
|
-
Options:
|
|
5
|
-
|
|
6
|
-
-h, --help Print this message.
|
|
7
|
-
-V, --version Print the package version.
|
|
8
|
-
--sep sep Separator used to join streamed data. Default: '\n'.
|
|
9
|
-
-n, --iter iterations Number of pseudorandom numbers.
|
|
10
|
-
--seed seed Pseudorandom number generator seed.
|
|
11
|
-
--state filepath Path to a file containing the pseudorandom number
|
|
12
|
-
generator state.
|
|
13
|
-
--snapshot filepath Output file path for saving the pseudorandom number
|
|
14
|
-
generator state upon exit.
|
|
15
|
-
|
package/etc/cli_opts.json
DELETED