JavaScript implementation of the XORSHIFT-ADD (XSadd) pseudo random number generator.
Based on the C code from https://github.com/MersenneTwister-Lab/XSadd.
$ npm install ml-xsadd
const { XSadd } = require("ml-xsadd");
const gen = new XSadd();
const number = gen.getFloat();
Creates a new XSadd instance. Seed is an optional integer that defaults to Date.now()
.
Returns a 32-bit integer r (0 <= r < 2^32).
Returns a floating point number r (0.0 <= r < 1.0).
Like getFloat()
but dynamically bound to the XSadd
instance.
You can use this function externally, like Math.random
:
const xsadd = new XSadd();
const random = xsadd.random;
const number = random();
Reinitialize the generator with a new seed.