random-bytes-seed
v2.0.0
Published
Get a random buffer based on a seed. Useful for reproducible tests
Downloads
14,123
Readme
random-bytes-seed
Get a random buffer based on a seed. Useful for reproducible tests.
npm install random-bytes-seed
Usage
var seed = require('random-bytes-seed')
var randomBytes = seed('a seed')
console.log(randomBytes(10)) // get 10 pseudo random bytes
console.log(randomBytes(20)) // get 20 pseudo random bytes
If you run the above example multiple times you'll notice it is returning the same "random" bytes every time because it is using the same seed. You should only use this for testing / debugging as there are probably some security problems with the way this is implemented ¯\(ツ)/¯.
When testing you can override crypto.randomBytes
with the seeded version like this
var crypto = require('crypto')
crypto.randomBytes = seed('a seed')
API
var randomBytes = seed([seed])
Create a new randomBytes generator. If you do not provide a seed a random one is chosen for you.
var buf = randomBytes(numberOfBytes)
Returns a new random buffer based on the seed.
randomBytes.seed
The seed originally used.
randomBytes.currentSeed
The seed for the next random operation.
License
MIT