Skip to content

Get a random buffer based on a seed. Useful for reproducible tests

License

Notifications You must be signed in to change notification settings

mafintosh/random-bytes-seed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random-bytes-seed

Get a random buffer based on a seed. Useful for reproducible tests.

npm install random-bytes-seed

build status

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

About

Get a random buffer based on a seed. Useful for reproducible tests

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published