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
* @param {boolean} FLG - flag indicating whether the state array was provided as an option (true) or an argument (false)
72
82
* @returns {(Error|null)} an error or `null`
73
83
*/
@@ -90,11 +100,11 @@ function verifyState( state, FLG ) {
90
100
if(state[1]!==NUM_STATE_SECTIONS){
91
101
returnnewRangeError(format('invalid %s. State array has an incompatible number of sections. Expected: `%s`. Actual: `%s`.',s1,NUM_STATE_SECTIONS,state[1]));
92
102
}
93
-
// The length of the "state" section must equal `1`...
94
-
if(state[STATE_SECTION_OFFSET]!==1){
95
-
returnnewRangeError(format('invalid %s. State array has an incompatible state length. Expected: `%u`. Actual: `%u`.',s1,1,state[STATE_SECTION_OFFSET]));
103
+
// The length of the "state" section must equal `N`...
104
+
if(state[STATE_SECTION_OFFSET]!==N){
105
+
returnnewRangeError(format('invalid %s. State array has an incompatible state length. Expected: `%u`. Actual: `%u`.',s1,2,state[STATE_SECTION_OFFSET]));
96
106
}
97
-
// The length of the "seed" section much match the empirical length...
107
+
// The length of the "seed" section must match the empirical length...
returnnewRangeError(format('invalid %s. State array length is incompatible with seed section length. Expected: `%u`. Actual: `%u`.',s1,state.length-STATE_FIXED_LENGTH,state[SEED_SECTION_OFFSET]));
100
110
}
@@ -112,9 +122,9 @@ function verifyState( state, FLG ) {
112
122
* @param {PRNGStateMINSTD} [options.state] - pseudorandom number generator state
113
123
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
114
124
* @throws {TypeError} options argument must be an object
115
-
* @throws {TypeError} a seed must be either a positive integer less than the maximum signed 32-bit integer or an array-like object containing integers less than the maximum signed 32-bit integer
116
-
* @throws {RangeError} a numeric seed must be a positive integer less than the maximum signed 32-bit integer
117
-
* @throws {TypeError} state must be an `Int32Array`
125
+
* @throws {TypeError} a seed must be either a positive integer less than the maximum unsigned 32-bit integer or an array-like object containing integers less than the maximum unsigned 32-bit integer
126
+
* @throws {RangeError} a numeric seed must be a positive integer less than the maximum unsigned 32-bit integer
127
+
* @throws {TypeError} state must be an `Uint32Array`
118
128
* @throws {Error} must provide a valid state
119
129
* @throws {TypeError} `copy` option must be a boolean
120
130
* @returns {PRNG} LCG PRNG
@@ -132,7 +142,7 @@ function verifyState( state, FLG ) {
132
142
* });
133
143
*
134
144
* var v = minstd();
135
-
* // returns 20739838
145
+
* // returns 2557507945
136
146
*/
137
147
functionfactory(options){
138
148
varSTATE;
@@ -156,8 +166,8 @@ function factory( options ) {
156
166
if(hasOwnProp(options,'state')){
157
167
state=options.state;
158
168
opts.state=true;
159
-
if(!isInt32Array(state)){
160
-
thrownewTypeError(format('invalid option. `%s` option must be an Int32Array. Option: `%s`.','state',state));
169
+
if(!isUint32Array(state)){
170
+
thrownewTypeError(format('invalid option. `%s` option must be an Uint32Array. Option: `%s`.','state',state));
161
171
}
162
172
err=verifyState(state,true);
163
173
if(err){
@@ -166,14 +176,14 @@ function factory( options ) {
// If provided a PRNG state, we ignore the `seed` option...
179
189
if(seed===void0){
@@ -182,68 +192,76 @@ function factory( options ) {
182
192
opts.seed=true;
183
193
if(isPositiveInteger(seed)){
184
194
if(seed>MAX_SEED){
185
-
thrownewRangeError(format('invalid option. `%s` option must be a positive integer less than the maximum signed 32-bit integer. Option: `%u`.','seed',seed));
195
+
thrownewRangeError(format('invalid option. `%s` option must be a positive integer less than the maximum unsigned 32-bit integer. Option: `%u`.','seed',seed));
186
196
}
187
-
seed|=0;// asm type annotation
197
+
seed>>>=0;// asm type annotation
188
198
}elseif(isCollection(seed)&&seed.length>0){
189
199
slen=seed.length;
190
-
STATE=newInt32Array(STATE_FIXED_LENGTH+slen);
200
+
STATE=newUint32Array(STATE_FIXED_LENGTH+slen);
191
201
192
202
// Initialize sections:
193
203
STATE[0]=STATE_ARRAY_VERSION;
194
204
STATE[1]=NUM_STATE_SECTIONS;
195
-
STATE[STATE_SECTION_OFFSET]=1;
205
+
STATE[STATE_SECTION_OFFSET]=N;
196
206
STATE[SEED_SECTION_OFFSET]=slen;
197
207
198
208
// Copy the provided seed array to prevent external mutation, as mutation would lead to an inability to reproduce PRNG values according to the PRNG's stated seed:
thrownewTypeError(format('invalid option. `%s` option must be either a positive integer less than the maximum signed 32-bit integer or an array-like object containing integer values less than the maximum signed 32-bit integer. Option: `%s`.','seed',seed));
225
+
thrownewTypeError(format('invalid option. `%s` option must be either a positive integer less than the maximum unsigned 32-bit integer or an array-like object containing integer values less than the maximum unsigned 32-bit integer. Option: `%s`.','seed',seed));
0 commit comments