rejection-sampled-int
v0.4.0
Published
Cryptographically random integers, chosen by a rejection sampling algorithm
Downloads
501
Readme
rejection-sampled-int
Cryptographically random integers, chosen by a rejection sampling algorithm.
Warning: I am not a cryptographer, or any sort of random number expert. An audit would be greatly appreciated.
Installation
To install the module for use in your projects:
npm install rejection-sampled-int
This library includes TypeScript definitions, and should be discovered automatically by the TypeScript compiler.
Usage
var rand = require('rejection-sampled-int')
rand.sync({max: 128}) // 56
rand.sync({min: 10, max: 16}) // 11
rand({min: 10, max: 16}, (err, int) => int) // 13
rand({min: 10, max: 16}).then(int => int) // 10
rand.sync() // 8882371922968183
API
rand({min = 0, max = Number.MAX_SAFE_INT}, [ready(err, int)])
Get an integer betweenmin
(inclusive) andmax
(exclusive). Ifready
is not provided, aPromise
is returned.rand.sync({min = 0, max = Number.MAX_SAFE_INT})
Get an integer betweenmin
(inclusive) andmax
(exclusive), synchronously.
License
MIT. See LICENSE for details.