Generate random bytes and numbers in Node.js and modern browsers with security in mind.
This small set of functions takes security serious and applies workarounds for JavaScript-specific quirks.
npm install random-bytes-numbers
Node.js:
var random_bytes_numbers = require('random-bytes-numbers')
// Do stuff
Browser:
requirejs(['random-bytes-numbers'], function (random_bytes_numbers) {
// Do stuff
})
Generate random bytes of specified size.
Generate random integer from range [min, max]
.
max - min
should be less or equal than Number.MAX_SAFE_INTEGER
, which is 53bits.
Replacement for Math.random()
that can be used for cryptographic operations, returns number from range [0, 1)
.
Feel free to create issues and send pull requests (for big changes create an issue first and link it from the PR), they are highly appreciated!
When reading LiveScript code make sure to configure 1 tab to be 4 spaces (GitHub uses 8 by default), otherwise code might be hard to read.
Free Public License 1.0.0 / Zero Clause BSD License