0.1.0 • Published 8 years ago
deterministic-pseudorandombytes v0.1.0
deterministic-pseudorandombytes
Stability: 1 - Experimental
Node.js crypto.randomBytes(size[, callback]) API compatible deterministic pseudorandom implementation.
Usage
const Generator = require("deterministic-pseudorandombytes");
const generator1 = new Generator({seed: "foo"});
const bytes1 = generator1.randomBytes(42);
const generator2 = new Generator({seed: "foo"});
const bytes2 = generator2.randomBytes(42);
const random = require("random-seed");
const generator3 = new Generator({random: random.create("foo")});
const bytes3 = generator3.randomBytes(42);
console.log(bytes1.equals(bytes2));
console.log(bytes1.equals(bytes3));
Overview
This module uses random-seed in order to generate deterministic pseudorandom bytes. The primary use-case for this is to support deterministic testing.
Documentation
Generator
new Generator(config)
config
: Objectrandom
: Object Initialized instance ofrandom-seed
generator. Mutually exclusive withconfig.seed
.seed
: String Seed to use to initialize a new instance ofrandom-seed
generator. Mutually exclusive withconfig.random
.
Creates a new Generator instance ready to serve random bytes.
generator.randomBytes(size, callback)
size
: Integer Number of bytes to generate.callback
: Function (Default: undefined)(error, buffer) => {}
Callback to invoke once bytes are generated.
Generates deterministic pseudorandom bytes. If callback
is not provided, bytes will returned synchronously as a Buffer.
0.1.0
8 years ago