SHISHUA: The fastest PRNG. A seedrandom-compatible random number generator.
npm install shishuaThe official page for SHISHUA is [here][SHISHUA].
This [npm][] package provides bindings for Node.js.
``js`
const shishua = require('shishua');
const buffer = Buffer.alloc(1 << 30); // 1 GiB
shishua().fill(buffer); // ~100ms on my laptop.
The package is API-compatible with [seedrandom][],
so that you can use it with the [random][] library:
`js
const random = require('random');
random.use(shishua('seed'));
// Build a Poisson sampling.
const poissonSample = random.poisson();
new Array(12).fill(0).map(poissonSample)
`
Returns a function that produces random floating-point values between 0
(included) and 1 (excluded).
The seed determines the sequence of numbers that this function returns:
`js`
new Array(3).fill(0).map(shishua('seed').int32)
// [ 1534767448, 1726267546, 2477584171 ]
new Array(3).fill(0).map(shishua('seed').int32)
// [ 1534767448, 1726267546, 2477584171 ]
new Array(3).fill(0).map(shishua('different seed, different values').int32)
// [ 69339860, 2922872123, 3883034659 ]
The seed can be either:
- A 32-byte Buffer, to map exactly to the functionality providedString
by the underlying SHISHUA algorithm,
- A , which is hashed into the 32-byte buffer,
- If not provided (or undefined),
a random seed is generated from the system's CSPRNG.
The other parameters, options and callback,
are only there for compatibility with [seedrandom][].
The object returned by calling shishua() also has the following methods,
which all tap into the stream generated by the seed:
- .fill(buffer), which fills a provided buffer with random bytes,.int32()
- , which generates a uniformly random 32-bit number,.double()
- , which produces a random floating-point value.quick()`, which also produces a random floating-point value
between 0 (included) and 1 (excluded),
-
between 0 (included) and 1 (excluded), but with only 32 bits of entropy.
[SHISHUA]: https://github.com/espadrine/shishua
[npm]: https://www.npmjs.com/package/shishua
[seedrandom]: https://www.npmjs.com/package/seedrandom
[random]: https://www.npmjs.com/package/random