# random-bytes-seed

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

Latest version **2.0.1** (published 2025-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-bytes-seed
pnpm add random-bytes-seed
yarn add random-bytes-seed
bun add random-bytes-seed
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-08-13 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/random-bytes-seed
- Repository: https://github.com/mafintosh/random-bytes-seed
- Issues: https://github.com/mafintosh/random-bytes-seed/issues
- npm.io page: https://npm.io/package/random-bytes-seed

## Dependencies (1)

- [sodium-universal](https://npm.io/package/sodium-universal.md) ^5.0.0

## Recent versions

- 2.0.1 (latest) — 2025-08-13
- 2.0.0 — 2024-06-27
- 1.0.3 — 2019-02-01
- 1.0.2 — 2016-09-30
- 1.0.1 — 2016-09-30
- 1.0.0 — 2016-09-30

## README

# random-bytes-seed

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

```
npm install random-bytes-seed
```

[![build status](http://img.shields.io/travis/mafintosh/random-bytes-seed.svg?style=flat)](http://travis-ci.org/mafintosh/random-bytes-seed)

## Usage

``` js
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

``` js
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

---
_Source: https://npm.io/package/random-bytes-seed · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
