Nodeschool Public Materials
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

seed-random

2.2.0 • Public • Published

seed-random

Generate random numbers with a seed, useful for reproducible tests

build status Dependency Status NPM version

Installation

$ npm install seed-random

API

var assert = require('assert');
var seed = require('../');
 
var trueRandomA = seed();
var trueRandomB = seed();
assert(trueRandomA() != trueRandomB());
 
var fakeRandomA = seed('foo');
var fakeRandomB = seed('foo');
assert(fakeRandomA() == fakeRandomB());
 
var fakeRandomC = seed('foo', {entropy: true});
var fakeRandomD = seed('foo', {entropy: true});
assert(fakeRandomC() != fakeRandomD());
 
 
seed('foo', {global: true});//over-ride global Math.random
var numA = Math.random();
seed('foo', {global: true});
var numB = Math.random();
assert(numA == numB);//always true
 
seed.resetGlobal();//reset to default Math.random

License

MIT

Keywords

none

install

npm i seed-random

Downloadsweekly downloads

104,621

version

2.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar