Constructor
new XORShift32(seed)
Implements the XORShift32 algorithm to generate pseudorandom numbers.
This class provides the XORShift32 method of generating psuedorandom numbers to the PRNG class. It uses bitwise operations to generate a sequence of pseudorandom 32-bit unsigned integers.
The XORShift algorithm was written by George Marsaglia in 2003 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.
Parameters:
Name | Type | Description |
---|---|---|
seed |
number | The seed value for the PRNG. |
- Implements:
- Source:
- See:
-
- Marsaglia, G. (2003) "XORShift RNGs", Journal of Statistical Software https://www.jstatsoft.org/article/view/v008i14
Example
const prng = new XORShift32(123456789);
console.log(prng.next()); // Generates a pseudorandom number
Classes
- XORShift32
Implements the XORShift32 algorithm to generate pseudorandom numbers.
Methods
next() → {number}
Generates the next psuedo-random number.
Returns:
A number in the range [0-1).
- Type
- number
Example
// Returns a random number in the range [0-1)
const rng = new XORShift32();
console.log(rng.next());