Skip to content

Commit 8d05628

Browse files
committed
Document properties and options
1 parent 7f29e6c commit 8d05628

File tree

1 file changed

+56
-0
lines changed
  • lib/node_modules/@stdlib/random/base/normal

1 file changed

+56
-0
lines changed

lib/node_modules/@stdlib/random/base/normal/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ r = rand( -2.0, 2.0 );
9191
The function accepts the following `options`:
9292

9393
- **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`.
9496

9597
To seed a pseudorandom number generator, set the `seed` option.
9698

@@ -113,6 +115,29 @@ var bool = ( r1 === r2 );
113115
// returns true
114116
```
115117

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:
137+
bool = ( rand( 1.0, 2.0 ) === normal( 1.0, 2.0 ) );
138+
// returns true
139+
```
140+
116141
#### normal.NAME
117142

118143
The generator name.
@@ -154,6 +179,15 @@ for ( i = 0; i < 100; i++ ) {
154179
}
155180
```
156181

182+
#### normal.seedLength
183+
184+
Length of generator seed.
185+
186+
```javascript
187+
var len = normal.seedLength;
188+
// returns <number>
189+
```
190+
157191
#### normal.state
158192

159193
Writable property for getting and setting the generator state.
@@ -190,6 +224,15 @@ r = normal( 2.0, 5.0 );
190224
// ...
191225
```
192226

227+
#### normal.stateLength
228+
229+
Length of generator state.
230+
231+
```javascript
232+
var len = normal.stateLength;
233+
// returns <number>
234+
```
235+
193236
#### normal.byteLength
194237

195238
Size of generator state.
@@ -203,6 +246,17 @@ var sz = normal.byteLength;
203246

204247
<!-- /.usage -->
205248

249+
<section class="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).
255+
256+
</section>
257+
258+
<!-- /.notes -->
259+
206260
<section class="examples">
207261

208262
## Examples
@@ -247,6 +301,8 @@ for ( i = 0; i < 100; i++ ) {
247301

248302
[normal]: https://en.wikipedia.org/wiki/Normal_distribution
249303

304+
[@stdlib/array/uint32]: https://github.com/stdlib-js/stdlib
305+
250306
</section>
251307

252308
<!-- /.links -->

0 commit comments

Comments
 (0)