https://github.com/vweevers/pseudo-random-buffer
Get a random buffer based on a seed. Fast, not secure.
https://github.com/vweevers/pseudo-random-buffer
bytes nodejs random xorshift
Last synced: 25 days ago
JSON representation
Get a random buffer based on a seed. Fast, not secure.
- Host: GitHub
- URL: https://github.com/vweevers/pseudo-random-buffer
- Owner: vweevers
- License: mit
- Created: 2019-06-01T17:56:29.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T04:08:57.000Z (about 6 years ago)
- Last Synced: 2025-10-27T04:39:05.528Z (8 months ago)
- Topics: bytes, nodejs, random, xorshift
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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`](https://github.com/mafintosh/random-bytes-seed) which uses [`crypto`](https://nodejs.org/api/crypto.html) (secure) while this uses [xorshift128+](https://github.com/AndreasMadsen/xorshift) (10-25x faster). See also [`pseudo-math-random`](https://github.com/vweevers/pseudo-math-random).
[](https://www.npmjs.org/package/pseudo-random-buffer)
[](https://www.npmjs.org/package/pseudo-random-buffer)
[](http://travis-ci.org/vweevers/pseudo-random-buffer)
[](https://standardjs.com)
## Usage
```js
const prb = require('pseudo-random-buffer')
const randomBytes = prb('a seed')
console.log(randomBytes(4)) //
console.log(randomBytes(3)) //
```
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](https://nodejs.org/api/buffer.html). 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](https://npmjs.org) 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](LICENSE.md) © 2019-present Vincent Weevers