pseudo-random-buffer

1.0.0 • Public • Published

pseudo-random-buffer

Get a random buffer based on a seed. Fast, not secure.
Useful for reproducible tests and benchmarks. Same API as random-bytes-seed which uses crypto (secure) while this uses xorshift128+ (10-25x faster). See also pseudo-math-random.

npm status node Travis build status JavaScript Style Guide

Usage

const prb = require('pseudo-random-buffer')
const randomBytes = prb('a seed')
 
console.log(randomBytes(4)) // <Buffer a3 e5 40 54>
console.log(randomBytes(3)) // <Buffer 09 14 6b>

This example will always log the same bytes, unless you change the seed.

API

randomBytes = prb([seed])

Create a new random bytes generator. The seed argument must be a string or Buffer. It is hashed once to counter short or zero-filled seeds. If no seed is provided one will be generated.

buf = randomBytes(length)

Get a buffer with pseudo random bytes.

Install

With npm do:

npm install pseudo-random-buffer

Benchmark

$ node benchmark.js 1024
node v10.14.1, n=1024

pseudo-random-buffer x 166,796 ops/sec ±1.68% (86 runs sampled)
random-bytes-seed x 13,477 ops/sec ±2.08% (76 runs sampled)

Fastest is pseudo-random-buffer

NB. Speed isn't everything. Decide for yourself which properties you need.

License

MIT © 2019-present Vincent Weevers

Package Sidebar

Install

npm i pseudo-random-buffer

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

5.12 kB

Total Files

4

Last publish

Collaborators

  • vweevers