The official page for SHISHUA is here.
This npm package provides bindings for Node.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:
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:
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 provided by the underlying SHISHUA algorithm, - A
String
, 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 between 0 (included) and 1 (excluded),.quick()
, which also produces a random floating-point value between 0 (included) and 1 (excluded), but with only 32 bits of entropy.