A deterministic number generator based on cryptographic hashing algorithms, with TypeScript typings.
$ npm install hbprng
import { Hbprng } from 'hbprng';
let generator = new Hbprng(Buffer.from('seed', 'utf8'), 'sha512');
console.log(generator.nextInt());
console.log(generator.nextInt());
console.log(generator.nextInt());
// Output:
// 3242175261
// 539230564
// 526738857
-
seed
: aBuffer
used to initialise the number generator -
hashAlg
: astring
representing the hashing algorithm used to derive the sequence. Defaults tosha256
. Please see the Node Crypto Docs for more information on available hashing algorithms.
Given the same seed
and hashAlg
, the generator will produce the same sequence.
Returns the next byte from the sequence.
Returns the next 32-bit unsigned integer from the sequence. Note that this method moves 4 bytes along the sequence.