You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/random/base/normal/README.md
+56
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,8 @@ r = rand( -2.0, 2.0 );
91
91
The function accepts the following `options`:
92
92
93
93
-**seed**: pseudorandom number generator seed.
94
+
-**state**: a [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
95
+
-**copy**: `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 generator has exclusive control over its internal state. Default: `true`.
94
96
95
97
To seed a pseudorandom number generator, set the `seed` option.
96
98
@@ -113,6 +115,29 @@ var bool = ( r1 === r2 );
113
115
// returns true
114
116
```
115
117
118
+
To return a generator having a specific initial state, set the generator `state` option.
119
+
120
+
```javascript
121
+
var rand;
122
+
var bool;
123
+
var r;
124
+
var i;
125
+
126
+
// Generate pseudorandom numbers, thus progressing the generator state:
127
+
for ( i =0; i <1000; i++ ) {
128
+
r =normal( 1.0, 2.0 );
129
+
}
130
+
131
+
// Create a new PRNG initialized to the current state of `normal`:
132
+
rand =normal.factory({
133
+
'state':normal.state
134
+
});
135
+
136
+
// Test that the generated pseudorandom numbers are the same:
@@ -154,6 +179,15 @@ for ( i = 0; i < 100; i++ ) {
154
179
}
155
180
```
156
181
182
+
#### normal.seedLength
183
+
184
+
Length of generator seed.
185
+
186
+
```javascript
187
+
var len =normal.seedLength;
188
+
// returns <number>
189
+
```
190
+
157
191
#### normal.state
158
192
159
193
Writable property for getting and setting the generator state.
@@ -190,6 +224,15 @@ r = normal( 2.0, 5.0 );
190
224
// ...
191
225
```
192
226
227
+
#### normal.stateLength
228
+
229
+
Length of generator state.
230
+
231
+
```javascript
232
+
var len =normal.stateLength;
233
+
// returns <number>
234
+
```
235
+
193
236
#### normal.byteLength
194
237
195
238
Size of generator state.
@@ -203,6 +246,17 @@ var sz = normal.byteLength;
203
246
204
247
<!-- /.usage -->
205
248
249
+
<sectionclass="notes">
250
+
251
+
## Notes
252
+
253
+
- If PRNG state is "shared" (meaning a state array was provided during PRNG creation and **not** copied) and one sets the generator state to a state array having a different length, the PRNG does **not** update the existing shared state and, instead, points to the newly provided state array. In order to synchronize PRNG output according to the new shared state array, the state array for **each** relevant PRNG must be **explicitly** set.
254
+
- If PRNG state is "shared" and one sets the generator state to a state array of the same length, the PRNG state is updated (along with the state of all other PRNGs sharing the PRNG's state array).
0 commit comments