davidbau / seedrandom

seeded random number generator for Javascript
2.06k stars 160 forks source link

Proposed new version #5

Closed davidbau closed 10 years ago

davidbau commented 10 years ago

This adds an options object so that you can set Math.random like this:

seedrandom('hello.', {global: true});
rng = seedrandom('hello.', {entropy: true});
rng = Math.seedrandom('hello.', {global:false});

Options include:

global -    true mutates Math.random and returns seed.
            false doesn't touch Math.random and returns PRNG.
            absent mimics old behavior (Math.seedrandom:true, module:false).
entropy -   true mixes entropy.
            false or absent doesn't mix entropy.
pass -      fn supplies a callback argument. calls
            fn(prng, seed, global)

The old calling conventions still work: you can pass a boolean as the second argument to be treated as "entropy: bool"; and you can pass the callback as the third arugment.