Skip to content

Commit e8bcc06

Browse files
committed
Document property and options
1 parent d812819 commit e8bcc06

File tree

1 file changed

+47
-0
lines changed
  • lib/node_modules/@stdlib/random/base/erlang

1 file changed

+47
-0
lines changed

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

+47
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ r = rand( 4, 3.14 );
102102
The function accepts the following `options`:
103103

104104
- **seed**: pseudorandom number generator seed.
105+
- **state**: a [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
106+
- **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`.
105107

106108
To seed a pseudorandom number generator, set the `seed` option.
107109

@@ -124,6 +126,29 @@ var bool = ( r1 === r2 );
124126
// returns true
125127
```
126128

129+
To return a generator having a specific initial state, set the generator `state` option.
130+
131+
```javascript
132+
var rand;
133+
var bool;
134+
var r;
135+
var i;
136+
137+
// Generate pseudorandom numbers, thus progressing the generator state:
138+
for ( i = 0; i < 1000; i++ ) {
139+
r = erlang( 2, 3.0 );
140+
}
141+
142+
// Create a new PRNG initialized to the current state of `erlang`:
143+
rand = erlang.factory({
144+
'state': erlang.state
145+
});
146+
147+
// Test that the generated pseudorandom numbers are the same:
148+
bool = ( rand( 2, 3.0 ) === erlang( 2, 3.0 ) );
149+
// returns true
150+
```
151+
127152
#### erlang.NAME
128153

129154
The generator name.
@@ -165,6 +190,15 @@ for ( i = 0; i < 100; i++ ) {
165190
}
166191
```
167192

193+
#### erlang.seedLength
194+
195+
Length of generator seed.
196+
197+
```javascript
198+
var len = erlang.seedLength;
199+
// returns <number>
200+
```
201+
168202
#### erlang.state
169203

170204
Writable property for getting and setting the generator state.
@@ -223,6 +257,17 @@ var sz = erlang.byteLength;
223257

224258
<!-- /.usage -->
225259

260+
<section class="notes">
261+
262+
## Notes
263+
264+
- 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.
265+
- 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).
266+
267+
</section>
268+
269+
<!-- /.notes -->
270+
226271
<section class="examples">
227272

228273
## Examples
@@ -267,6 +312,8 @@ for ( i = 0; i < 100; i++ ) {
267312

268313
[erlang]: https://en.wikipedia.org/wiki/Erlang_distribution
269314

315+
[@stdlib/array/uint32]: https://github.com/stdlib-js/stdlib
316+
270317
</section>
271318

272319
<!-- /.links -->

0 commit comments

Comments
 (0)