All files main.js

100% Statements 90/90
100% Branches 1/1
100% Functions 0/0
100% Lines 90/90

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 912x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
'use strict';
 
// MODULES //
 
var factory = require( './factory.js' );
var randuint32 = require( './rand_uint32.js' );
 
 
// MAIN //
 
/**
* Generates a pseudorandom unsigned 32-bit integer via the xorshift32 algorithm.
*
* ## Method
*
* XorShift generators are a class of pseudorandom number generators discovered
* by George Marsaglia. They operate by repeated application of the exclusive or
* (XOR) operation combined with bit shifts.
*
* The xorshift32 algorithm uses the state recurrence
*
* ```tex
* x \leftarrow x \oplus (x \ll a_1) \\
* x \leftarrow x \oplus (x \gg a_2) \\
* x \leftarrow x \oplus (x \ll a_3)
* ```
*
* where \\(\oplus\\) denotes the bitwise exclusive or operator and the shift
* triplet \\((a_1, a_2, a_3)\\) is chosen to ensure the generator has a full
* period of \\(2^{32} - 1\\).
*
* In this implementation, the shift triplet is
*
* ```tex
* (a_1, a_2, a_3) = (13, 17, 5)
* ```
*
* as proposed by Marsaglia (2003). The state must be a non-zero unsigned 32-bit
* integer; a zero seed is replaced with \\(1\\) to avoid the degenerate
* all-zeros state.
*
* ## Notes
*
* -   The generator has a period of \\(2^{32} - 1\\) (all non-zero 32-bit states
*     are visited exactly once before the sequence repeats).
*
* -   The output range is between 1 to 2^32 - 1 (zero is never produced).
*
* -   The `normalized` property returns values on \\((0, 1]\\) by dividing the
*     raw output by \\(2^{32} - 1\\).
*
* ## References
*
* -   Marsaglia, George. 2003. "Xorshift RNGs." _Journal of Statistical
*     Software_ 8 (14). doi:[10.18637/jss.v008.i14](https://doi.org/10.18637/jss.v008.i14).
*
* @function xorshift32
* @type {PRNG}
* @returns {NonNegativeInteger} pseudorandom unsigned 32-bit integer
*
* @example
* var v = xorshift32();
* // returns <number>
*/
var xorshift32 = factory({
	'seed': randuint32()
});
 
 
// EXPORTS //
 
module.exports = xorshift32;