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/erlang/README.md
+47
Original file line number
Diff line number
Diff line change
@@ -102,6 +102,8 @@ r = rand( 4, 3.14 );
102
102
The function accepts the following `options`:
103
103
104
104
-**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`.
105
107
106
108
To seed a pseudorandom number generator, set the `seed` option.
107
109
@@ -124,6 +126,29 @@ var bool = ( r1 === r2 );
124
126
// returns true
125
127
```
126
128
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
+
127
152
#### erlang.NAME
128
153
129
154
The generator name.
@@ -165,6 +190,15 @@ for ( i = 0; i < 100; i++ ) {
165
190
}
166
191
```
167
192
193
+
#### erlang.seedLength
194
+
195
+
Length of generator seed.
196
+
197
+
```javascript
198
+
var len =erlang.seedLength;
199
+
// returns <number>
200
+
```
201
+
168
202
#### erlang.state
169
203
170
204
Writable property for getting and setting the generator state.
@@ -223,6 +257,17 @@ var sz = erlang.byteLength;
223
257
224
258
<!-- /.usage -->
225
259
260
+
<sectionclass="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).
0 commit comments