random-bytes-seed

1.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i random-bytes-seed

Weekly Downloads

398

Version

1.0.3

License

MIT

Unpacked Size

4.49 kB

Total Files

7

Last publish

Collaborators

  • mafintosh