61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
// A library of seedable RNGs implemented in Javascript.
|
|
//
|
|
// Usage:
|
|
//
|
|
// var seedrandom = require('seedrandom');
|
|
// var random = seedrandom(1); // or any seed.
|
|
// var x = random(); // 0 <= x < 1. Every bit is random.
|
|
// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness.
|
|
|
|
// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe.
|
|
// Period: ~2^116
|
|
// Reported to pass all BigCrush tests.
|
|
var alea = require('./lib/alea');
|
|
|
|
// xor128, a pure xor-shift generator by George Marsaglia.
|
|
// Period: 2^128-1.
|
|
// Reported to fail: MatrixRank and LinearComp.
|
|
var xor128 = require('./lib/xor128');
|
|
|
|
// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl.
|
|
// Period: 2^192-2^32
|
|
// Reported to fail: CollisionOver, SimpPoker, and LinearComp.
|
|
var xorwow = require('./lib/xorwow');
|
|
|
|
// xorshift7, by François Panneton and Pierre L'ecuyer, takes
|
|
// a different approach: it adds robustness by allowing more shifts
|
|
// than Marsaglia's original three. It is a 7-shift generator
|
|
// with 256 bits, that passes BigCrush with no systmatic failures.
|
|
// Period 2^256-1.
|
|
// No systematic BigCrush failures reported.
|
|
var xorshift7 = require('./lib/xorshift7');
|
|
|
|
// xor4096, by Richard Brent, is a 4096-bit xor-shift with a
|
|
// very long period that also adds a Weyl generator. It also passes
|
|
// BigCrush with no systematic failures. Its long period may
|
|
// be useful if you have many generators and need to avoid
|
|
// collisions.
|
|
// Period: 2^4128-2^32.
|
|
// No systematic BigCrush failures reported.
|
|
var xor4096 = require('./lib/xor4096');
|
|
|
|
// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random
|
|
// number generator derived from ChaCha, a modern stream cipher.
|
|
// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
|
|
// Period: ~2^127
|
|
// No systematic BigCrush failures reported.
|
|
var tychei = require('./lib/tychei');
|
|
|
|
// The original ARC4-based prng included in this library.
|
|
// Period: ~2^1600
|
|
var sr = require('./seedrandom');
|
|
|
|
sr.alea = alea;
|
|
sr.xor128 = xor128;
|
|
sr.xorwow = xorwow;
|
|
sr.xorshift7 = xorshift7;
|
|
sr.xor4096 = xor4096;
|
|
sr.tychei = tychei;
|
|
|
|
module.exports = sr;
|