Skip to content

Commit fe46a43

Browse files
committed
Add seedLength property for returning the seed length
1 parent 1f45523 commit fe46a43

File tree

5 files changed

+132
-73
lines changed

5 files changed

+132
-73
lines changed

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

+22-13
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ var str = mt19937.NAME;
118118
// returns 'mt19937'
119119
```
120120

121+
#### mt19937.MIN
122+
123+
Minimum possible value.
124+
125+
```javascript
126+
var min = mt19937.MIN;
127+
// returns 1
128+
```
129+
130+
#### mt19937.MAX
131+
132+
Maximum possible value.
133+
134+
```javascript
135+
var max = mt19937.MAX;
136+
// returns 4294967295
137+
```
138+
121139
#### mt19937.seed
122140

123141
The value used to seed `mt19937()`.
@@ -141,22 +159,13 @@ for ( i = 0; i < 100; i++ ) {
141159
}
142160
```
143161

144-
#### mt19937.MIN
145-
146-
Minimum possible value.
147-
148-
```javascript
149-
var min = mt19937.MIN;
150-
// returns 1
151-
```
152-
153-
#### mt19937.MAX
162+
#### mt19937.seedLength
154163

155-
Maximum possible value.
164+
Length of generator seed.
156165

157166
```javascript
158-
var max = mt19937.MAX;
159-
// returns 4294967295
167+
var len = mt19937.seedLength;
168+
// returns <number>
160169
```
161170

162171
#### mt19937.state

lib/node_modules/@stdlib/random/base/mt19937/docs/repl.txt

+16-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@
8383
'mt19937'
8484

8585

86-
{{alias}}.seed
87-
Pseudorandom number generator seed.
88-
89-
Examples
90-
--------
91-
> var seed = {{alias}}.seed;
92-
93-
9486
{{alias}}.MIN
9587
Minimum possible value.
9688

@@ -109,6 +101,22 @@
109101
4294967295
110102

111103

104+
{{alias}}.seed
105+
Pseudorandom number generator seed.
106+
107+
Examples
108+
--------
109+
> var seed = {{alias}}.seed;
110+
111+
112+
{{alias}}.seedLength
113+
Length of generator seed.
114+
115+
Examples
116+
--------
117+
> var len = {{alias}}.seedLength;
118+
119+
112120
{{alias}}.state
113121
Generator state.
114122

lib/node_modules/@stdlib/random/base/mt19937/lib/factory.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ function factory( options ) {
437437
'enumerable': true,
438438
'get': getSeed
439439
});
440+
defineProperty( mt19937, 'seedLength', {
441+
'configurable': false,
442+
'enumerable': true,
443+
'get': getSeedLength
444+
});
440445
defineProperty( mt19937, 'state', {
441446
'configurable': false,
442447
'enumerable': true,
@@ -463,6 +468,11 @@ function factory( options ) {
463468
'enumerable': true,
464469
'get': getSeed
465470
});
471+
defineProperty( normalized, 'seedLength', {
472+
'configurable': false,
473+
'enumerable': true,
474+
'get': getSeedLength
475+
});
466476
defineProperty( normalized, 'state', {
467477
'configurable': false,
468478
'enumerable': true,
@@ -495,7 +505,17 @@ function factory( options ) {
495505
}
496506

497507
/**
498-
* Returns the current PRNG state length.
508+
* Returns the PRNG seed length.
509+
*
510+
* @private
511+
* @returns {PositiveInteger} seed length
512+
*/
513+
function getSeedLength() {
514+
return slen;
515+
}
516+
517+
/**
518+
* Returns the PRNG state length.
499519
*
500520
* @private
501521
* @returns {PositiveInteger} state length
@@ -505,7 +525,7 @@ function factory( options ) {
505525
}
506526

507527
/**
508-
* Returns the current PRNG state size (in bytes).
528+
* Returns the PRNG state size (in bytes).
509529
*
510530
* @private
511531
* @returns {PositiveInteger} state size (in bytes)

lib/node_modules/@stdlib/random/base/mt19937/test/test.factory.js

+40-28
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,19 @@ tape( 'the function returns a seeded pseudorandom number generator (array seed)'
310310

311311
tape( 'attached to the returned function is the generator name', function test( t ) {
312312
var mt19937 = factory();
313-
t.equal( mt19937.NAME, 'mt19937', 'has `NAME` property' );
313+
t.equal( mt19937.NAME, 'mt19937', 'has property' );
314+
t.end();
315+
});
316+
317+
tape( 'attached to the returned function is the minimum possible generated number', function test( t ) {
318+
var mt19937 = factory();
319+
t.equal( mt19937.MIN, 1, 'has property' );
320+
t.end();
321+
});
322+
323+
tape( 'attached to the returned function is the maximum possible generated number', function test( t ) {
324+
var mt19937 = factory();
325+
t.equal( mt19937.MAX, UINT32_MAX, 'has property' );
314326
t.end();
315327
});
316328

@@ -323,7 +335,7 @@ tape( 'attached to the returned function is the generator seed (integer seed)',
323335
});
324336
actual = mt19937.seed;
325337

326-
t.equal( isUint32Array( actual ), true, 'has `seed` property' );
338+
t.equal( isUint32Array( actual ), true, 'has property' );
327339
t.equal( actual.length, 1, 'has expected length' );
328340
t.equal( actual[ 0 ], 12345, 'equal to provided seed' );
329341
t.end();
@@ -341,40 +353,34 @@ tape( 'attached to the returned function is the generator seed (array seed)', fu
341353
});
342354

343355
actual = mt19937.seed;
344-
t.equal( isUint32Array( actual ), true, 'has `seed` property' );
356+
t.equal( isUint32Array( actual ), true, 'has property' );
345357
for ( i = 0; i < seed.length; i++ ) {
346358
t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i );
347359
}
348360
t.end();
349361
});
350362

351-
tape( 'attached to the returned function is the minimum possible generated number', function test( t ) {
352-
var mt19937 = factory();
353-
t.equal( mt19937.MIN, 1, 'has `MIN` property' );
354-
t.end();
355-
});
356-
357-
tape( 'attached to the returned function is the maximum possible generated number', function test( t ) {
363+
tape( 'attached to the returned function is the generator seed length', function test( t ) {
358364
var mt19937 = factory();
359-
t.equal( mt19937.MAX, UINT32_MAX, 'has `MAX` property' );
365+
t.equal( typeof mt19937.seedLength, 'number', 'has property' );
360366
t.end();
361367
});
362368

363369
tape( 'attached to the returned function is the generator state', function test( t ) {
364370
var mt19937 = factory();
365-
t.equal( isUint32Array( mt19937.state ), true, 'has `state` property' );
371+
t.equal( isUint32Array( mt19937.state ), true, 'has property' );
366372
t.end();
367373
});
368374

369375
tape( 'attached to the returned function is the generator state length', function test( t ) {
370376
var mt19937 = factory();
371-
t.equal( typeof mt19937.stateLength, 'number', 'has `stateLength` property' );
377+
t.equal( typeof mt19937.stateLength, 'number', 'has property' );
372378
t.end();
373379
});
374380

375381
tape( 'attached to the returned function is the generator state size', function test( t ) {
376382
var mt19937 = factory();
377-
t.equal( typeof mt19937.byteLength, 'number', 'has `byteLength` property' );
383+
t.equal( typeof mt19937.byteLength, 'number', 'has property' );
378384
t.end();
379385
});
380386

@@ -449,7 +455,19 @@ tape( 'attached to the returned function is a `normalized` method for generating
449455

450456
tape( 'attached to the `normalized` method is the generator name', function test( t ) {
451457
var mt19937 = factory();
452-
t.equal( mt19937.normalized.NAME, 'mt19937', 'has `NAME` property' );
458+
t.equal( mt19937.normalized.NAME, 'mt19937', 'has property' );
459+
t.end();
460+
});
461+
462+
tape( 'attached to the `normalized` method is the minimum possible generated number', function test( t ) {
463+
var mt19937 = factory();
464+
t.equal( mt19937.normalized.MIN, 0.0, 'has property' );
465+
t.end();
466+
});
467+
468+
tape( 'attached to the `normalized` method is the maximum possible generated number', function test( t ) {
469+
var mt19937 = factory();
470+
t.equal( mt19937.normalized.MAX, FLOAT64_MAX_SAFE_INTEGER/(FLOAT64_MAX_SAFE_INTEGER+1), 'has property' );
453471
t.end();
454472
});
455473

@@ -462,7 +480,7 @@ tape( 'attached to the `normalized` method is the generator seed (integer seed)'
462480
});
463481
actual = mt19937.normalized.seed;
464482

465-
t.equal( isUint32Array( actual ), true, 'has `seed` property' );
483+
t.equal( isUint32Array( actual ), true, 'has property' );
466484
t.equal( actual.length, 1, 'has expected length' );
467485
t.equal( actual[ 0 ], 12345, 'equal to provided seed' );
468486
t.end();
@@ -480,40 +498,34 @@ tape( 'attached to the `normalized` method is the generator seed (array seed)',
480498
});
481499

482500
actual = mt19937.normalized.seed;
483-
t.equal( isUint32Array( actual ), true, 'has `seed` property' );
501+
t.equal( isUint32Array( actual ), true, 'has property' );
484502
for ( i = 0; i < seed.length; i++ ) {
485503
t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i );
486504
}
487505
t.end();
488506
});
489507

490-
tape( 'attached to the `normalized` method is the minimum possible generated number', function test( t ) {
491-
var mt19937 = factory();
492-
t.equal( mt19937.normalized.MIN, 0.0, 'has `MIN` property' );
493-
t.end();
494-
});
495-
496-
tape( 'attached to the `normalized` method is the maximum possible generated number', function test( t ) {
508+
tape( 'attached to the `normalized` method is the generator seed length', function test( t ) {
497509
var mt19937 = factory();
498-
t.equal( mt19937.normalized.MAX, FLOAT64_MAX_SAFE_INTEGER/(FLOAT64_MAX_SAFE_INTEGER+1), 'has `MAX` property' );
510+
t.equal( typeof mt19937.normalized.seedLength, 'number', 'has property' );
499511
t.end();
500512
});
501513

502514
tape( 'attached to the `normalized` method is the generator state', function test( t ) {
503515
var mt19937 = factory();
504-
t.equal( isUint32Array( mt19937.normalized.state ), true, 'has `state` property' );
516+
t.equal( isUint32Array( mt19937.normalized.state ), true, 'has property' );
505517
t.end();
506518
});
507519

508520
tape( 'attached to the `normalized` method is the generator state size', function test( t ) {
509521
var mt19937 = factory();
510-
t.equal( typeof mt19937.normalized.byteLength, 'number', 'has `byteLength` property' );
522+
t.equal( typeof mt19937.normalized.byteLength, 'number', 'has property' );
511523
t.end();
512524
});
513525

514526
tape( 'attached to the `normalized` method is the generator state length', function test( t ) {
515527
var mt19937 = factory();
516-
t.equal( typeof mt19937.normalized.stateLength, 'number', 'has `stateLength` property' );
528+
t.equal( typeof mt19937.normalized.stateLength, 'number', 'has property' );
517529
t.end();
518530
});
519531

0 commit comments

Comments
 (0)