├── .gitignore ├── support ├── c │ ├── mash.h │ ├── Alea.c │ ├── LFib.c │ ├── Xorshift03.c │ ├── LFIB4.c │ ├── Kybos.c │ ├── KISS07.c │ └── MRG32k3a.c └── js │ ├── Mash.js │ ├── index.js │ ├── Invwk.js │ ├── Alea.js │ ├── Xorshift03.js │ ├── LFib.js │ ├── LFIB4.js │ ├── KISS07.js │ ├── Kybos.js │ └── MRG32k3a.js ├── docs ├── src │ ├── index.js │ └── renderHistogram.js ├── webpack.config.js └── index.html ├── webpack.config.js ├── package.json ├── LICENSE.md ├── index.js ├── dist ├── prng.min.js └── prng.min.js.map └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /support/c/mash.h: -------------------------------------------------------------------------------- 1 | static inline double mash(unsigned char *x) { 2 | static uint32_t n = 0xefc8249d; 3 | double h; 4 | 5 | while (*x) { 6 | n += *x++; 7 | h = 0.02519603282416938 * n; 8 | n = h; 9 | h -= n; 10 | h *= n; 11 | n = h; 12 | h -= n; 13 | n += h * 0x100000000ULL; 14 | } 15 | return n * 2.3283064365386963e-10; // 2^-32 16 | } -------------------------------------------------------------------------------- /support/js/Mash.js: -------------------------------------------------------------------------------- 1 | // From http://baagoe.com/en/RandomMusings/javascript/ 2 | // Johannes Baagøe , 2010 3 | export default function Mash() { 4 | var n = 0xefc8249d; 5 | 6 | var mash = function (data) { 7 | data = data.toString(); 8 | for (var i = 0; i < data.length; i++) { 9 | n += data.charCodeAt(i); 10 | var h = 0.02519603282416938 * n; 11 | n = h >>> 0; 12 | h -= n; 13 | h *= n; 14 | n = h >>> 0; 15 | h -= n; 16 | n += h * 0x100000000; // 2^32 17 | } 18 | return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 19 | }; 20 | 21 | mash.version = 'Mash 0.9'; 22 | return mash; 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /docs/src/index.js: -------------------------------------------------------------------------------- 1 | import * as normalize from '../../node_modules/skeleton-css/css/normalize.css'; 2 | import * as skeletoncss from '../../node_modules/skeleton-css/css/skeleton.css'; 3 | import * as _ from 'lodash'; 4 | import PRNG from '../../support/js/index'; 5 | import renderHistogram from './renderHistogram'; 6 | import * as d3 from 'd3'; 7 | 8 | let seed = +new Date; 9 | let numSamples = 100000; 10 | 11 | function renderAlg(alg) { 12 | let data = _.times(numSamples, PRNG[alg](seed).bind(this, undefined, undefined)) 13 | renderHistogram(`#${alg}`, data); 14 | } 15 | 16 | renderAlg('Alea'); 17 | renderAlg('KISS07'); 18 | renderAlg('Kybos'); 19 | renderAlg('LFib'); 20 | renderAlg('LFib4'); 21 | renderAlg('MRG32k3a'); 22 | renderAlg('Xorshift03'); 23 | renderAlg('Invwk'); 24 | 25 | // let AleaData = _.times(numSamples, PRNG.Alea(seed).bind(this, undefined, undefined)); 26 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var argv = require('yargs').argv; 3 | 4 | module.exports = { 5 | context: __dirname, 6 | devtool: !argv.commonjs ? (argv.hot ? "#eval" : "#source-map") : undefined, 7 | entry: './support/js/index.js', 8 | output: { 9 | filename: argv.commonjs ? './index.js' : './dist/prng.min.js', 10 | library: !argv.commonjs ? 'PRNG' : undefined, 11 | libraryTarget: argv.commonjs ? 'commonjs2' : 'var' 12 | }, 13 | plugins: [ 14 | new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) 15 | ], 16 | module: { 17 | loaders: [ 18 | { 19 | test: /\.js$/, 20 | exclude: /node_modules/, 21 | loader: 'babel', 22 | query: { 23 | presets: ['latest'] 24 | } 25 | } 26 | ], 27 | } 28 | }; -------------------------------------------------------------------------------- /support/c/Alea.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | const double norm32 = 2.3283064365386963e-10; // 2^-32 6 | 7 | static double s0, s1, s2; 8 | static int c = 1; 9 | 10 | static inline double alea() { 11 | double t = 2091639.0 * s0 + c * norm32; // 2^-32 12 | s0 = s1; 13 | s1 = s2; 14 | return s2 = t - (c = t); 15 | } 16 | 17 | int main(int argc, unsigned char *argv[]) { 18 | double buffer[256]; 19 | int i; 20 | 21 | s0 = mash(" "); 22 | s1 = mash(" "); 23 | s2 = mash(" "); 24 | 25 | for (i = 1; i < argc; i++) { 26 | s0 -= mash(argv[i]); 27 | if (s0 < 0.0) { 28 | s0 += 1.0; 29 | } 30 | s1 -= mash(argv[i]); 31 | if (s1 < 0.0) { 32 | s1 += 1.0; 33 | } 34 | s2 -= mash(argv[i]); 35 | if (s2 < 0.0) { 36 | s2 += 1.0; 37 | } 38 | } 39 | 40 | while (1) { 41 | for (i = 0; i < 256; i++) { 42 | buffer[i] = alea(); 43 | } 44 | fwrite(buffer, sizeof buffer, 1, stdout); 45 | } 46 | } -------------------------------------------------------------------------------- /support/c/LFib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | const double norm21 = 4.76837158203125e-7; // 2^-21 6 | 7 | static double s[256]; 8 | static uint8_t k0 = 255, k1 = 52, k2 = 0; 9 | 10 | static inline double lfib(void) { 11 | double x; 12 | 13 | k0++; 14 | k1++; 15 | k2++; 16 | 17 | x = s[k0] - s[k1]; 18 | if/span> (x < 0.0) { 19 | x += 1.0; 20 | } 21 | x -= s[k2]; 22 | if (x < 0.0) { 23 | x += 1.0; 24 | } 25 | return s[k0] = x; 26 | } 27 | 28 | int main(int argc, unsigned char *argv[]) { 29 | double buffer[256]; 30 | int i, j; 31 | 32 | for (j = 0; j < 256; j++) { 33 | s[j] = mash(" "); 34 | s[j] -= mash(" ") * norm21; // 2^-21 35 | if (s[j] < 0.0) { 36 | s[j] += 1.0; 37 | } 38 | } 39 | for (i = 1; i < argc; i++) { 40 | for (j = 0; j < 256; j++) { 41 | s[j] -= mash(argv[i]); 42 | s[j] -= mash(argv[i]) * norm21; // 2^-21 43 | if (s[j] < 0.0) { 44 | s[j] += 1.0; 45 | } 46 | } 47 | } 48 | 49 | while (1) { 50 | for (i = 0; i < 256; i++) { 51 | buffer[i] = lfib(); 52 | } 53 | fwrite(buffer, sizeof buffer, 1, stdout); 54 | } 55 | } -------------------------------------------------------------------------------- /support/c/Xorshift03.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | // George Marsaglia, 13 May 2003 6 | // http://groups.google.com/group/comp.lang.c/msg/e3c4ea1169e463ae 7 | 8 | const double norm32 = 2.3283064365386963e-10; // 2^-32 9 | 10 | static uint32_t x = 123456789, y = 362436069, 11 | z = 521288629, w = 88675123, v = 886756453; 12 | 13 | double xorshift03(void) { 14 | unsigned long t; 15 | t = (x ^ (x >> 7)); 16 | x = y; 17 | y = z; 18 | z = w; 19 | w = v; 20 | v = (v ^ (v << 6)) ^ (t ^ (t << 13)); 21 | return (y + y + 1#41; * v * norm32; // 2^-32 22 | } 23 | 24 | int main(int argc, unsigned char *argv[]) { 25 | double buffer[256]; 26 | int i; 27 | 28 | for (i = 1; i < argc; i++) { 29 | x ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 30 | y ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 31 | z ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 32 | v ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 33 | w ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 34 | } 35 | 36 | while (1) { 37 | for (i = 0; i < 256; i++) { 38 | buffer[i] = xorshift03(); 39 | } 40 | fwrite(buffer, sizeof buffer, 1, stdout); 41 | } 42 | } -------------------------------------------------------------------------------- /support/js/index.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | import Invwk from './Invwk'; 3 | import Alea from './Alea'; 4 | import KISS07 from './KISS07'; 5 | import Kybos from './Kybos'; 6 | import LFib from './LFib'; 7 | import LFib4 from './LFIB4'; 8 | import MRG32k3a from './MRG32k3a'; 9 | import Xorshift03 from './Xorshift03'; 10 | 11 | function random(generator) { 12 | var rand = null; 13 | return function () { 14 | var args = Array.prototype.slice.call(arguments); 15 | rand = args.length 16 | ? generator.apply(this, args) 17 | : generator(); 18 | 19 | function range(from, to) { 20 | if (typeof from !== 'undefined' && typeof to === 'undefined') { 21 | return from * rand() | 0; 22 | } else if (typeof from !== 'undefined' && typeof to !== 'undefined') { 23 | return ((to - from) * rand() + from) | 0; 24 | } else { 25 | return rand(); 26 | } 27 | } 28 | 29 | return Object.assign(range, rand); 30 | } 31 | } 32 | 33 | let rand = random(Alea); 34 | rand.Invwk = random(Invwk); 35 | rand.Mash = Mash; 36 | rand.Alea = random(Alea); 37 | rand.KISS07 = random(KISS07); 38 | rand.Kybos = random(Kybos); 39 | rand.LFib = random(LFib); 40 | rand.LFib4 = random(LFib4); 41 | rand.MRG32k3a = random(MRG32k3a); 42 | rand.Xorshift03 = random(Xorshift03); 43 | 44 | module.exports = rand; -------------------------------------------------------------------------------- /support/js/Invwk.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | 4 | //Webkit2's crazy invertible mapping generator 5 | //Based on Andy Hyland's implementation: https://bocoup.com/weblog/random-numbers 6 | export default function Invwk() { 7 | var args = Array.prototype.slice.call(arguments); 8 | var mash = Mash(); 9 | var max = 0x100000000; // 2 ^ 32 10 | 11 | if (args.length == 0) { 12 | args = [+new Date]; 13 | } 14 | 15 | var seed = (mash(args.join('')) * max) | 0; 16 | // var seed = (Math.random() * max) | 0; 17 | 18 | var random = function () { 19 | seed += (seed * seed) | 5; 20 | // Shift off bits, discarding the sign. Discarding the sign is 21 | // important because OR w/ 5 can give us + or - numbers. 22 | return (seed >>> 32) * 2.3283064365386963e-10; 23 | }; 24 | 25 | random.uint32 = function () { 26 | seed += (seed * seed) | 5; 27 | // Shift off bits, discarding the sign. Discarding the sign is 28 | // important because OR w/ 5 can give us + or - numbers. 29 | return (seed >>> 0); 30 | }; 31 | random.fract53 = function () { 32 | return random() + 33 | (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 34 | }; 35 | random.version = 'Alea 0.9'; 36 | random.args = args; 37 | 38 | return random; 39 | }; -------------------------------------------------------------------------------- /support/c/LFIB4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | // George Marsaglia's LFIB4, 6 | //http://groups.google.com/group/sci.crypt/msg/eb4ddde782b17051 7 | const double norm21 = 4.76837158203125e-7; // 2^-21 8 | 9 | static double s[256]; 10 | static uint8_t k0 = 0, k1 = 58, k2 = 119, k3 = 178; 11 | 12 | static inline double lfib4(void) { 13 | double x; 14 | 15 | k0++; 16 | k1++; 17 | k2++; 18 | k3++; 19 | 20 | x = s[k0] - s[k1]; 21 | if (x < 0.0) { 22 | x += 1.0; 23 | } 24 | x -= s[k2]; 25 | if (x < 0.0) { 26 | x += 1.0; 27 | } 28 | x -= s[k3]; 29 | if (x < 0.0) { 30 | x += 1.0; 31 | } 32 | 33 | return s[k0] = x; 34 | } 35 | 36 | int main(int argc, unsigned char *argv[]) { 37 | double buffer[256]; 38 | int i, j; 39 | 40 | for (j = 0; j < 256; j++) { 41 | s[j] = mash(" "); 42 | s[j] -= mash(" ") * norm21; // 2^-21 43 | if (s[j] < 0.0) { 44 | s[j] += 1.0; 45 | } 46 | } 47 | for (i = 1; i < argc; i++) { 48 | for (j = 0; j < 256; j++) { 49 | s[j] -= mash(argv[i]); 50 | s[j] -= mash(argv[i]) * norm21; // 2^-21 51 | if (s[j] < 0.0) { 52 | s[j] += 1.0; 53 | } 54 | } 55 | } 56 | 57 | while (1) { 58 | for (i = 0; i < 256; i++) { 59 | buffer[i] = lfib4(); 60 | } 61 | fwrite(buffer, sizeof buffer, 1, stdout); 62 | } 63 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prng", 3 | "version": "1.0.0", 4 | "description": "A collection of pseudorandom number generators by Johannes Baagøe's.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build:script": "webpack", 9 | "build:node": "webpack --commonjs", 10 | "dev": "webpack --watch --hot", 11 | "serve": "webpack-dev-server --inline --hot" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/dworthen/prng.git" 16 | }, 17 | "keywords": [ 18 | "prng", 19 | "random", 20 | "pseudorandom number generators", 21 | "alea", 22 | "kiss", 23 | "kybos", 24 | "lfib", 25 | "lfib4", 26 | "mrg32k3a", 27 | "xorshift" 28 | ], 29 | "author": "dworthen", 30 | "license": "See license.md", 31 | "bugs": { 32 | "url": "https://github.com/dworthen/prng/issues" 33 | }, 34 | "homepage": "https://github.com/dworthen/prng#readme", 35 | "devDependencies": { 36 | "babel-core": "*", 37 | "babel-loader": "*", 38 | "babel-preset-latest": "*", 39 | "css-loader": "*", 40 | "d3": "^4.4.0", 41 | "file-loader": "*", 42 | "lodash": "^4.17.2", 43 | "skeleton-css": "^2.0.4", 44 | "style-loader": "*", 45 | "url-loader": "*", 46 | "webpack": "*", 47 | "webpack-dev-server": "*", 48 | "yargs": "*" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /support/js/Alea.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | 4 | // From http://baagoe.com/en/RandomMusings/javascript/ 5 | export default function Alea () { 6 | // Johannes Baagøe , 2010 7 | var args = Array.prototype.slice.call(arguments); 8 | var s0 = 0; 9 | var s1 = 0; 10 | var s2 = 0; 11 | var c = 1; 12 | 13 | if (args.length == 0) { 14 | args = [+new Date]; 15 | } 16 | var mash = Mash(); 17 | s0 = mash(' '); 18 | s1 = mash(' '); 19 | s2 = mash(' '); 20 | 21 | for (var i = 0; i < args.length; i++) { 22 | s0 -= mash(args[i]); 23 | if (s0 < 0) { 24 | s0 += 1; 25 | } 26 | s1 -= mash(args[i]); 27 | if (s1 < 0) { 28 | s1 += 1; 29 | } 30 | s2 -= mash(args[i]); 31 | if (s2 < 0) { 32 | s2 += 1; 33 | } 34 | } 35 | mash = null; 36 | 37 | var random = function () { 38 | var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32 39 | s0 = s1; 40 | s1 = s2; 41 | return s2 = t - (c = t | 0); 42 | }; 43 | random.uint32 = function () { 44 | return random() * 0x100000000; // 2^32 45 | }; 46 | random.fract53 = function () { 47 | return random() + 48 | (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 49 | }; 50 | random.version = 'Alea 0.9'; 51 | random.args = args; 52 | return random; 53 | 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /support/js/Xorshift03.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function Xorshift03() { 5 | // George Marsaglia, 13 May 2003 6 | // http://groups.google.com/group/comp.lang.c/msg/e3c4ea1169e463ae 7 | var args = Array.prototype.slice.call(arguments); 8 | var x = 123456789, 9 | y = 362436069, 10 | z = 521288629, 11 | w = 88675123, 12 | v = 886756453; 13 | 14 | if (args.length == 0) { 15 | args = [+new Date]; 16 | } 17 | var mash = Mash(); 18 | for (var i = 0; i < args.length; i++) { 19 | x ^= mash(args[i]) * 0x100000000; // 2^32 20 | y ^= mash(args[i]) * 0x100000000; 21 | z ^= mash(args[i]) * 0x100000000; 22 | v ^= mash(args[i]) * 0x100000000; 23 | w ^= mash(args[i]) * 0x100000000; 24 | } 25 | mash = null; 26 | 27 | var uint32 = function () { 28 | var t = (x ^ (x >>> 7)) >>> 0; 29 | x = y; 30 | y = z; 31 | z = w; 32 | w = v; 33 | v = (v ^ (v << 6)) ^ (t ^ (t << 13)) >>> 0; 34 | return ((y + y + 1) * v) >>> 0; 35 | } 36 | 37 | var random = function () { 38 | return uint32() * 2.3283064365386963e-10; // 2^-32 39 | }; 40 | random.uint32 = uint32; 41 | random.fract53 = function () { 42 | return random() + 43 | (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53 44 | }; 45 | random.version = 'Xorshift03 0.9'; 46 | random.args = args; 47 | return random; 48 | 49 | }; -------------------------------------------------------------------------------- /support/js/LFib.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function LFib() { 5 | // Johannes Baagøe , 2010 6 | var args = Array.prototype.slice.call(arguments); 7 | var k0 = 255, 8 | k1 = 52, 9 | k2 = 0; 10 | var s = []; 11 | 12 | var mash = Mash(); 13 | if (args.length === 0) { 14 | args = [+new Date()]; 15 | } 16 | for (var j = 0; j < 256; j++) { 17 | s[j] = mash(' '); 18 | s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21 19 | if (s[j] < 0) { 20 | s[j] += 1; 21 | } 22 | } 23 | for (var i = 0; i < args.length; i++) { 24 | for (var j = 0; j < 256; j++) { 25 | s[j] -= mash(args[i]); 26 | s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21 27 | if (s[j] < 0) { 28 | s[j] += 1; 29 | } 30 | } 31 | } 32 | mash = null; 33 | 34 | var random = function () { 35 | k0 = (k0 + 1) & 255; 36 | k1 = (k1 + 1) & 255; 37 | k2 = (k2 + 1) & 255; 38 | 39 | var x = s[k0] - s[k1]; 40 | if (x < 0.0) { 41 | x += 1.0; 42 | } 43 | x -= s[k2]; 44 | if (x < 0.0) { 45 | x += 1.0; 46 | } 47 | return s[k0] = x; 48 | } 49 | 50 | random.uint32 = function () { 51 | return random() * 0x100000000 >>> 0; // 2^32 52 | }; 53 | random.fract53 = random; 54 | random.version = 'LFib 0.9'; 55 | random.args = args; 56 | 57 | return random; 58 | }; -------------------------------------------------------------------------------- /support/c/Kybos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | const double norm32 = 2.3283064365386963e-10; // 2^-32 6 | 7 | static double s0, s1, s2; 8 | static int c = 1; 9 | 10 | static inline double alea() { 11 | double t = 2091639.0 * s0 + c * norm32; // 2^-32 12 | s0 = s1; 13 | s1 = s2; 14 | return s2 = t - (c = t); 15 | } 16 | 17 | static double s[8]; 18 | static int k = 0; 19 | 20 | static inline double kybos() { 21 | double r; 22 | 23 | k = s[k] * 8.0; 24 | r = s[k]; 25 | s[k] -= alea(); 26 | if (s[k] < 0) { 27 | s[k] += 1; 28 | } 29 | return r; 30 | } 31 | 32 | int main(int argc, unsigned char *argv[]) { 33 | double buffer[256]; 34 | int i, j; 35 | 36 | s0 = mash(" "); 37 | s1 = mash(" "); 38 | s2 = mash(" "); 39 | for (j = 0; j < 8; j++) { 40 | s[j] = mash(" "); 41 | } 42 | 43 | for (i = 1; i < argc; i++) { 44 | s0 -= mash(argv[i]); 45 | if (s0 < 0.0) { 46 | s0 += 1.0; 47 | } 48 | s1 -= mash(argv[i]); 49 | if (s1 < 0.0) { 50 | s1 += 1.0; 51 | } 52 | s2 -= mash(argv[i]); 53 | if (s2 < 0.0) { 54 | s2 += 1.0; 55 | } 56 | for (j = 0; j < 8; j++) { 57 | s[j] -= mash(argv[i]); 58 | if (s[j] < 0.0) { 59 | s[j] += 1.0; 60 | } 61 | } 62 | } 63 | 64 | while (1) { 65 | for (i = 0; i < 256; i++) { 66 | buffer[i] = kybos(); 67 | } 68 | fwrite(buffer, sizeof buffer, 1, stdout); 69 | } 70 | } -------------------------------------------------------------------------------- /support/c/KISS07.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | // George Marsaglia, 2007-06-23 6 | //http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5 7 | 8 | const double norm32 = 2.3283064365386963e-10; // 2^-32 9 | 10 | static uint32_t x = 123456789; 11 | static uint32_t y = 362436069; 12 | static uint32_t z = 21288629; 13 | static uint32_t w = 14921776; 14 | static uint32_t c = 0; 15 | 16 | static inline double kiss07(void) { 17 | uint32_t t; 18 | 19 | x += 545925293; 20 | 21 | y ^= y << 13; 22 | y ^= y >> 17; 23 | y ^= y << 5; 24 | 25 | t = z + w + c; 26 | z = w; 27 | c = t >> 31; 28 | w = t & 0x7fffffff; 29 | 30 | return (x + y + w) * norm32; // 2^-32; 31 | } 32 | 33 | int main(int argc, unsigned char *argv[]) { 34 | double buffer[256]; 35 | int i; 36 | 37 | for (i = 1; i < argc; i++) { 38 | x ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 39 | y ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 40 | z ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 41 | w ^= (uint32_t) (mash(argv[i]) * 0x100000000ULL); // 2^32 42 | } 43 | if (y == 0) { 44 | y = 1; 45 | } 46 | c ^= z >> 31; 47 | z &= 0x7fffffff; 48 | if ((z % 7559) == 0) { 49 | z++; 50 | } 51 | w &= 0x7fffffff; 52 | if ((w % 7559) == 0) { 53 | w++; 54 | } 55 | 56 | while (1) { 57 | for (i = 0; i < 256; i++) { 58 | buffer[i] = kiss07(); 59 | } 60 | fwrite(buffer, sizeof buffer, 1, stdout); 61 | } 62 | } -------------------------------------------------------------------------------- /support/js/LFIB4.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function LFIB4() { 5 | // George Marsaglia's LFIB4, 6 | //http://groups.google.com/group/sci.crypt/msg/eb4ddde782b17051 7 | var args = Array.prototype.slice.call(arguments); 8 | var k0 = 0, 9 | k1 = 58, 10 | k2 = 119, 11 | k3 = 178; 12 | 13 | var s = []; 14 | 15 | var mash = Mash(); 16 | if (args.length === 0) { 17 | args = [+new Date()]; 18 | } 19 | for (var j = 0; j < 256; j++) { 20 | s[j] = mash(' '); 21 | s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21 22 | if (s[j] < 0) { 23 | s[j] += 1; 24 | } 25 | } 26 | for (var i = 0; i < args.length; i++) { 27 | for (var j = 0; j < 256; j++) { 28 | s[j] -= mash(args[i]); 29 | s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21 30 | if (s[j] < 0) { 31 | s[j] += 1; 32 | } 33 | } 34 | } 35 | mash = null; 36 | 37 | var random = function () { 38 | var x; 39 | 40 | k0 = (k0 + 1) & 255; 41 | k1 = (k1 + 1) & 255; 42 | k2 = (k2 + 1) & 255; 43 | k3 = (k3 + 1) & 255; 44 | 45 | x = s[k0] - s[k1]; 46 | if (x < 0) { 47 | x += 1; 48 | } 49 | x -= s[k2]; 50 | if (x < 0) { 51 | x += 1; 52 | } 53 | x -= s[k3]; 54 | if (x < 0) { 55 | x += 1; 56 | } 57 | 58 | return s[k0] = x; 59 | } 60 | 61 | random.uint32 = function () { 62 | return random() * 0x100000000 >>> 0; // 2^32 63 | }; 64 | random.fract53 = random; 65 | random.version = 'LFIB4 0.9'; 66 | random.args = args; 67 | 68 | return random; 69 | }; -------------------------------------------------------------------------------- /support/js/KISS07.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function KISS07() { 5 | // George Marsaglia, 2007-06-23 6 | //http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5 7 | var args = Array.prototype.slice.call(arguments); 8 | var x = 123456789; 9 | var y = 362436069; 10 | var z = 21288629; 11 | var w = 14921776; 12 | var c = 0; 13 | 14 | if (args.length == 0) { 15 | args = [+new Date]; 16 | } 17 | var mash = Mash(); 18 | for (var i = 0; i < args.length; i++) { 19 | x ^= mash(args[i]) * 0x100000000; // 2^32 20 | y ^= mash(args[i]) * 0x100000000; 21 | z ^= mash(args[i]) * 0x100000000; 22 | w ^= mash(args[i]) * 0x100000000; 23 | } 24 | if (y === 0) { 25 | y = 1; 26 | } 27 | c ^= z >>> 31; 28 | z &= 0x7fffffff; 29 | if ((z % 7559) === 0) { 30 | z++; 31 | } 32 | w &= 0x7fffffff; 33 | if ((w % 7559) === 0) { 34 | w++; 35 | } 36 | mash = null; 37 | 38 | var uint32 = function () { 39 | var t; 40 | 41 | x += 545925293; 42 | x >>>= 0; 43 | 44 | y ^= y << 13; 45 | y ^= y >>> 17; 46 | y ^= y << 5; 47 | 48 | t = z + w + c; 49 | z = w; 50 | c = t >>> 31; 51 | w = t & 0x7fffffff; 52 | 53 | return x + y + w >>> 0; 54 | }; 55 | 56 | var random = function () { 57 | return uint32() * 2.3283064365386963e-10; // 2^-32 58 | }; 59 | random.uint32 = uint32; 60 | random.fract53 = function () { 61 | return random() + 62 | (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53 63 | }; 64 | random.args = args; 65 | random.version = 'KISS07 0.9'; 66 | 67 | return random; 68 | }; 69 | 70 | -------------------------------------------------------------------------------- /docs/src/renderHistogram.js: -------------------------------------------------------------------------------- 1 | import * as d3 from 'd3'; 2 | 3 | export default function renderHistogram(id, data) { 4 | 5 | var formatCount = d3.format(",.0f"); 6 | 7 | var svg = d3.select(id), 8 | margin = { top: 10, right: 30, bottom: 30, left: 30 }, 9 | width = +svg.attr("width") - margin.left - margin.right, 10 | height = +svg.attr("height") - margin.top - margin.bottom, 11 | g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); 12 | 13 | var x = d3.scaleLinear() 14 | .rangeRound([0, width]); 15 | 16 | var bins = d3.histogram() 17 | .domain(x.domain()) 18 | .thresholds(x.ticks(20)) 19 | (data); 20 | 21 | var y = d3.scaleLinear() 22 | .domain([0, d3.max(bins, function (d) { return d.length; })]) 23 | .range([height, 0]); 24 | 25 | var bar = g.selectAll(".bar") 26 | .data(bins) 27 | .enter().append("g") 28 | .attr("class", "bar") 29 | .attr("transform", function (d) { return "translate(" + x(d.x0) + "," + y(d.length) + ")"; }); 30 | 31 | bar.append("rect") 32 | .attr("x", 1) 33 | .attr("width", x(bins[0].x1) - x(bins[0].x0) - 1) 34 | .attr("height", function (d) { return height - y(d.length); }); 35 | 36 | bar.append("text") 37 | .attr("dy", ".75em") 38 | .attr("y", 6) 39 | .attr("x", (x(bins[0].x1) - x(bins[0].x0)) / 2) 40 | .attr("text-anchor", "middle") 41 | .text(function (d) { return formatCount(d.length); }); 42 | 43 | g.append("g") 44 | .attr("class", "axis axis--x") 45 | .attr("transform", "translate(0," + height + ")") 46 | .call(d3.axisBottom(x)); 47 | } -------------------------------------------------------------------------------- /docs/webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var argv = require('yargs').argv; 3 | 4 | module.exports = { 5 | context: __dirname, 6 | devtool: argv.hot ? "#eval" : "#source-map", 7 | entry: './src/index.js', 8 | output: { 9 | filename: './app.min.js', 10 | library: 'PRNG', 11 | libraryTarget: 'var' 12 | }, 13 | plugins: [ 14 | new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) 15 | ], 16 | module: { 17 | loaders: [ 18 | { 19 | test: /\.js$/, 20 | exclude: /node_modules/, 21 | loader: 'babel', 22 | query: { 23 | presets: ['latest'] 24 | } 25 | }, 26 | { 27 | test: /\.css$/, 28 | loader: 'style!css' 29 | }, 30 | { 31 | test: /\.(jpg|png|gif)$/, 32 | loader: 'url' 33 | }, 34 | { 35 | test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, 36 | loader: "url?mimetype=application/font-woff" 37 | }, 38 | { 39 | test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, 40 | loader: "url?mimetype=application/font-woff" 41 | }, 42 | { 43 | test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 44 | loader: "url?mimetype=application/octet-stream" 45 | }, 46 | { 47 | test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 48 | loader: "url?mimetype=application/vnd.ms-fontobject" 49 | }, 50 | { 51 | test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 52 | loader: "url?mimetype=image/svg+xml" 53 | } 54 | ], 55 | } 56 | }; -------------------------------------------------------------------------------- /support/js/Kybos.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function Kybos() { 5 | // Johannes Baagøe , 2010 6 | var args = Array.prototype.slice.call(arguments); 7 | var s0 = 0; 8 | var s1 = 0; 9 | var s2 = 0; 10 | var c = 1; 11 | var s = []; 12 | var k = 0; 13 | 14 | var mash = Mash(); 15 | var s0 = mash(' '); 16 | var s1 = mash(' '); 17 | var s2 = mash(' '); 18 | for (var j = 0; j < 8; j++) { 19 | s[j] = mash(' '); 20 | } 21 | 22 | if (args.length == 0) { 23 | args = [+new Date]; 24 | } 25 | for (var i = 0; i < args.length; i++) { 26 | s0 -= mash(args[i]); 27 | if (s0 < 0) { 28 | s0 += 1; 29 | } 30 | s1 -= mash(args[i]); 31 | if (s1 < 0) { 32 | s1 += 1; 33 | } 34 | s2 -= mash(args[i]); 35 | if (s2 < 0) { 36 | s2 += 1; 37 | } 38 | for (var j = 0; j < 8; j++) { 39 | s[j] -= mash(args[i]); 40 | if (s[j] < 0) { 41 | s[j] += 1; 42 | } 43 | } 44 | } 45 | 46 | var random = function () { 47 | var a = 2091639; 48 | k = s[k] * 8 | 0; 49 | var r = s[k]; 50 | var t = a * s0 + c * 2.3283064365386963e-10; // 2^-32 51 | s0 = s1; 52 | s1 = s2; 53 | s2 = t - (c = t | 0); 54 | s[k] -= s2; 55 | if (s[k] < 0) { 56 | s[k] += 1; 57 | } 58 | return r; 59 | }; 60 | random.uint32 = function () { 61 | return random() * 0x100000000; // 2^32 62 | }; 63 | random.fract53 = function () { 64 | return random() + 65 | (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 66 | }; 67 | random.addNoise = function () { 68 | for (var i = arguments.length - 1; i >= 0; i--) { 69 | for (j = 0; j < 8; j++) { 70 | s[j] -= mash(arguments[i]); 71 | if (s[j] < 0) { 72 | s[j] += 1; 73 | } 74 | } 75 | } 76 | }; 77 | random.version = 'Kybos 0.9'; 78 | random.args = args; 79 | return random; 80 | 81 | }; 82 | -------------------------------------------------------------------------------- /support/c/MRG32k3a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mash.h" 4 | 5 | // Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. 6 | // http://www.iro.umontreal.ca/~lecuyer/ 7 | #define norm 2.328306549295728e-10 8 | #define m1 4294967087.0 9 | #define m2 4294944443.0 10 | #define a12 1403580.0 11 | #define a13n 810728.0 12 | #define a21 527612.0 13 | #define a23n 1370589.0 14 | 15 | static double s10 = 12345, s11 = 12345, s12 = 123, 16 | s20 = 12345, s21 = 12345, s22 = 123; 17 | 18 | double MRG32k3a(void) { 19 | long k; 20 | double p1, p2; 21 | /* Component 1 */ 22 | p1 = a12 * s11 - a13n * s10; 23 | k = p1 / m1; 24 | p1 -= k * m1; 25 | if (p1 < 0.0) 26 | p1 += m1; 27 | s10 = s11; 28 | s11 = s12; 29 | s12 = p1; 30 | /* Component 2 */ 31 | p2 = a21 * s22 - a23n * s20; 32 | k = p2 / m2; 33 | p2 -= k * m2; 34 | if (p2 < 0.0) 35 | p2 += m2; 36 | s20 = s21; 37 | s21 = s22; 38 | s22 = p2; 39 | /* Combination */ 40 | if (p1 <= p2) 41 | return ((p1 - p2 + m1) * norm); 42 | else 43 | return ((p1 - p2) * norm); 44 | } 45 | 46 | int main(int argc, unsigned char *argv[]) { 47 | double buffer[256]; 48 | int i; 49 | 50 | for (i = 1; i < argc; i++) { 51 | s10 += mash(argv[i]) * 0x100000000ULL; // 2^32 52 | s11 += mash(argv[i]) * 0x100000000ULL; // 2^32 53 | s12 += mash(argv[i]) * 0x100000000ULL; // 2^32 54 | s20 += mash(argv[i]) * 0x100000000ULL; // 2^32 55 | s21 += mash(argv[i]) * 0x100000000ULL; // 2^32 56 | s22 += mash(argv[i]) * 0x100000000ULL; // 2^32 57 | } 58 | 59 | s10 = (uint64_t) s10 % (uint32_t) m1; 60 | s11 = (uint64_t) s11 % (uint32_t) m1; 61 | s12 = (uint64_t) s12 % (uint32_t) m1; 62 | s20 = (uint64_t) s20 % (uint32_t) m2; 63 | s21 = (uint64_t) s21 % (uint32_t) m2; 64 | s22 = (uint64_t) s22 % (uint32_t) m2; 65 | 66 | while (1) { 67 | for (i = 0; i < 256; i++) { 68 | buffer[i] = MRG32k3a(); 69 | } 70 | fwrite(buffer, sizeof buffer, 1, stdout); 71 | } 72 | } -------------------------------------------------------------------------------- /support/js/MRG32k3a.js: -------------------------------------------------------------------------------- 1 | import Mash from './Mash'; 2 | 3 | // From http://baagoe.com/en/RandomMusings/javascript/ 4 | export default function MRG32k3a() { 5 | // Copyright (c) 1998, 2002 Pierre L'Ecuyer, DIRO, Université de Montréal. 6 | // http://www.iro.umontreal.ca/~lecuyer/ 7 | var args = Array.prototype.slice.call(arguments); 8 | var m1 = 4294967087; 9 | var m2 = 4294944443; 10 | var s10 = 12345, 11 | s11 = 12345, 12 | s12 = 123, 13 | s20 = 12345, 14 | s21 = 12345, 15 | s22 = 123; 16 | 17 | if (args.length === 0) { 18 | args = [+new Date()]; 19 | } 20 | var mash = Mash(); 21 | for (var i = 0; i < args.length; i++) { 22 | s10 += mash(args[i]) * 0x100000000; // 2 ^ 32 23 | s11 += mash(args[i]) * 0x100000000; 24 | s12 += mash(args[i]) * 0x100000000; 25 | s20 += mash(args[i]) * 0x100000000; 26 | s21 += mash(args[i]) * 0x100000000; 27 | s22 += mash(args[i]) * 0x100000000; 28 | } 29 | s10 %= m1; 30 | s11 %= m1; 31 | s12 %= m1; 32 | s20 %= m2; 33 | s21 %= m2; 34 | s22 %= m2; 35 | mash = null; 36 | 37 | var uint32 = function () { 38 | var m1 = 4294967087; 39 | var m2 = 4294944443; 40 | var a12 = 1403580; 41 | var a13n = 810728; 42 | var a21 = 527612; 43 | var a23n = 1370589; 44 | 45 | var k, p1, p2; 46 | 47 | /* Component 1 */ 48 | p1 = a12 * s11 - a13n * s10; 49 | k = p1 / m1 | 0; 50 | p1 -= k * m1; 51 | if (p1 < 0) p1 += m1; 52 | s10 = s11; 53 | s11 = s12; 54 | s12 = p1; 55 | 56 | /* Component 2 */ 57 | p2 = a21 * s22 - a23n * s20; 58 | k = p2 / m2 | 0; 59 | p2 -= k * m2; 60 | if (p2 < 0) p2 += m2; 61 | s20 = s21; 62 | s21 = s22; 63 | s22 = p2; 64 | 65 | /* Combination */ 66 | if (p1 <= p2) return p1 - p2 + m1; 67 | else return p1 - p2; 68 | }; 69 | 70 | var random = function () { 71 | return uint32() * 2.3283064365386963e-10; // 2^-32 72 | }; 73 | random.uint32 = uint32; 74 | random.fract53 = function () { 75 | return random() + 76 | (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53 77 | }; 78 | random.version = 'MRG32k3a 0.9'; 79 | random.args = args; 80 | 81 | return random; 82 | }; -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | _Note: This is a direct mirror of Johannes Baagøe's wiki on implementations of Randomness in Javascript. [Mr. Baagøe's site](http://baagoe.org/) has largely disappeared from the internet this is a faithful reproduction of it from [Archive.org](https://web.archive.org/web/20120124013936/http://baagoe.org/en/wiki/Better_random_numbers_for_javascript) and other sources. The content is Licensed as per his wiki, [Creative Commons Attribution Share Alike](http://creativecommons.org/licenses/by-sa/3.0/), additional licenses for code are as follows._ 2 | 3 | `MRG32k3a` is [copyrighted](http://www.iro.umontreal.ca/~simardr/testu01/copyright.html) as a part of [TestU01](http://www.iro.umontreal.ca/~simardr/testu01/tu01.html). 4 | 5 | The status of `Xorshift03`, `KISS07` and `LFIB4` is somewhat unclear. The sources are Usenet posts, and one of them explicitly states ["You 6 | are welcome to use one or both of the above"](http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5). It seems unlikely that Professor Marsaglia intended to restrict their use in any way, but on the other hand, I have no indication that he ever formally released them to the public domain. 7 | 8 | My own work is licensed according to the [MIT - Expat license](http://en.wikipedia.org/wiki/MIT_License): 9 | 10 | Copyright (C) 2010 by Johannes Baagøe 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pseudo Random Number Generators in JavaScript 6 | 7 | 131 | 150 | 151 | 152 | 153 |
154 | 155 | 156 |
157 |

Pseudo-Random Number Generators in JavaScript

158 | 159 |
160 | 161 |

32 Bit Fraction Test

162 | 163 |
Alea
164 | 165 | 166 | 167 |
KISS07
168 | 169 | 170 | 171 |
Kybos
172 | 173 | 174 | 175 |
LFib
176 | 177 | 178 | 179 |
LFib4
180 | 181 | 182 | 183 |
MRG32k3a
184 | 185 | 186 | 187 |
Xorshift03
188 | 189 | 190 | 191 |
Invwk
192 | 193 | 194 | 195 |
196 | 197 |
198 | 199 | 200 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports=function(e){function t(n){if(r[n])return r[n].exports;var u=r[n]={exports:{},id:n,loaded:!1};return e[n].call(u.exports,u,u.exports,t),u.loaded=!0,u.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(e){var t=null;return function(){function r(e,r){return"undefined"!=typeof e&&"undefined"==typeof r?e*t()|0:"undefined"!=typeof e&&"undefined"!=typeof r?(r-e)*t()+e|0:t()}var n=Array.prototype.slice.call(arguments);return t=n.length?e.apply(this,n):e(),Object.assign(r,t)}}var a=r(1),o=n(a),f=r(2),l=n(f),i=r(3),c=n(i),s=r(4),d=n(s),v=r(5),p=n(v),_=r(6),y=n(_),g=r(7),h=n(g),M=r(8),b=n(M),A=r(9),j=n(A),O=u(l.default);O.Invwk=u(l.default),O.Mash=o.default,O.Alea=u(c.default),O.KISS07=u(d.default),O.Kybos=u(p.default),O.LFib=u(y.default),O.LFib4=u(h.default),O.MRG32k3a=u(b.default),O.Xorshift03=u(j.default),e.exports=O},function(e,t){"use strict";function r(){var e=4022871197,t=function(t){t=t.toString();for(var r=0;r>>0,n-=e,n*=e,e=n>>>0,n-=e,e+=4294967296*n}return 2.3283064365386963e-10*(e>>>0)};return t.version="Mash 0.9",t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),t=(0,o.default)(),r=4294967296;0==e.length&&(e=[+new Date]);var n=t(e.join(""))*r|0,u=function(){return n+=n*n|5,2.3283064365386963e-10*(n>>>32)};return u.uint32=function(){return n+=n*n|5,n>>>0},u.fract53=function(){return u()+1.1102230246251565e-16*(2097152*u()|0)},u.version="Alea 0.9",u.args=e,u}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),t=0,r=0,n=0,u=1;0==e.length&&(e=[+new Date]);var a=(0,o.default)();t=a(" "),r=a(" "),n=a(" ");for(var f=0;f>>31,n&=2147483647,n%7559===0&&n++,u&=2147483647,u%7559===0&&u++,f=null;var i=function(){var e;return t+=545925293,t>>>=0,r^=r<<13,r^=r>>>17,r^=r<<5,e=n+u+a,n=u,a=e>>>31,u=2147483647&e,t+r+u>>>0},c=function(){return 2.3283064365386963e-10*i()};return c.uint32=i,c.fract53=function(){return c()+1.1102230246251565e-16*(2097151&i())},c.args=e,c.version="KISS07 0.9",c}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){for(var e=Array.prototype.slice.call(arguments),t=0,r=0,n=0,u=1,a=[],f=0,l=(0,o.default)(),t=l(" "),r=l(" "),n=l(" "),i=0;i<8;i++)a[i]=l(" ");0==e.length&&(e=[+new Date]);for(var c=0;c=0;e--)for(i=0;i<8;i++)a[i]-=l(arguments[e]),a[i]<0&&(a[i]+=1)},s.version="Kybos 0.9",s.args=e,s}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),t=255,r=52,n=0,u=[],a=(0,o.default)();0===e.length&&(e=[+new Date]);for(var f=0;f<256;f++)u[f]=a(" "),u[f]-=4.76837158203125e-7*a(" "),u[f]<0&&(u[f]+=1);for(var l=0;l>>0},i.fract53=i,i.version="LFib 0.9",i.args=e,i}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),t=0,r=58,n=119,u=178,a=[],f=(0,o.default)();0===e.length&&(e=[+new Date]);for(var l=0;l<256;l++)a[l]=f(" "),a[l]-=4.76837158203125e-7*f(" "),a[l]<0&&(a[l]+=1);for(var i=0;i>>0},c.fract53=c,c.version="LFIB4 0.9",c.args=e,c}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),t=4294967087,r=4294944443,n=12345,u=12345,a=123,f=12345,l=12345,i=123;0===e.length&&(e=[+new Date]);for(var c=(0,o.default)(),s=0;s>>7)>>>0;return t=r,r=n,n=u,u=a,a=a^a<<6^(e^e<<13)>>>0,(r+r+1)*a>>>0},c=function(){return 2.3283064365386963e-10*i()};return c.uint32=i,c.fract53=function(){return c()+1.1102230246251565e-16*(2097151&i())},c.version="Xorshift03 0.9",c.args=e,c}Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var a=r(1),o=n(a)}]); -------------------------------------------------------------------------------- /dist/prng.min.js: -------------------------------------------------------------------------------- 1 | var PRNG=function(e){function r(n){if(t[n])return t[n].exports;var u=t[n]={exports:{},id:n,loaded:!1};return e[n].call(u.exports,u,u.exports,r),u.loaded=!0,u.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(e){var r=null;return function(){function t(e,t){return"undefined"!=typeof e&&"undefined"==typeof t?e*r()|0:"undefined"!=typeof e&&"undefined"!=typeof t?(t-e)*r()+e|0:r()}var n=Array.prototype.slice.call(arguments);return r=n.length?e.apply(this,n):e(),Object.assign(t,r)}}var a=t(1),o=n(a),f=t(2),l=n(f),i=t(3),c=n(i),s=t(4),d=n(s),v=t(5),p=n(v),_=t(6),y=n(_),g=t(7),h=n(g),M=t(8),b=n(M),A=t(9),j=n(A),O=u(l.default);O.Invwk=u(l.default),O.Mash=o.default,O.Alea=u(c.default),O.KISS07=u(d.default),O.Kybos=u(p.default),O.LFib=u(y.default),O.LFib4=u(h.default),O.MRG32k3a=u(b.default),O.Xorshift03=u(j.default),e.exports=O},function(e,r){"use strict";function t(){var e=4022871197,r=function(r){r=r.toString();for(var t=0;t>>0,n-=e,n*=e,e=n>>>0,n-=e,e+=4294967296*n}return 2.3283064365386963e-10*(e>>>0)};return r.version="Mash 0.9",r}Object.defineProperty(r,"__esModule",{value:!0}),r.default=t},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),r=(0,o.default)(),t=4294967296;0==e.length&&(e=[+new Date]);var n=r(e.join(""))*t|0,u=function(){return n+=n*n|5,2.3283064365386963e-10*(n>>>32)};return u.uint32=function(){return n+=n*n|5,n>>>0},u.fract53=function(){return u()+1.1102230246251565e-16*(2097152*u()|0)},u.version="Alea 0.9",u.args=e,u}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),r=0,t=0,n=0,u=1;0==e.length&&(e=[+new Date]);var a=(0,o.default)();r=a(" "),t=a(" "),n=a(" ");for(var f=0;f>>31,n&=2147483647,n%7559===0&&n++,u&=2147483647,u%7559===0&&u++,f=null;var i=function(){var e;return r+=545925293,r>>>=0,t^=t<<13,t^=t>>>17,t^=t<<5,e=n+u+a,n=u,a=e>>>31,u=2147483647&e,r+t+u>>>0},c=function(){return 2.3283064365386963e-10*i()};return c.uint32=i,c.fract53=function(){return c()+1.1102230246251565e-16*(2097151&i())},c.args=e,c.version="KISS07 0.9",c}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){for(var e=Array.prototype.slice.call(arguments),r=0,t=0,n=0,u=1,a=[],f=0,l=(0,o.default)(),r=l(" "),t=l(" "),n=l(" "),i=0;i<8;i++)a[i]=l(" ");0==e.length&&(e=[+new Date]);for(var c=0;c=0;e--)for(i=0;i<8;i++)a[i]-=l(arguments[e]),a[i]<0&&(a[i]+=1)},s.version="Kybos 0.9",s.args=e,s}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),r=255,t=52,n=0,u=[],a=(0,o.default)();0===e.length&&(e=[+new Date]);for(var f=0;f<256;f++)u[f]=a(" "),u[f]-=4.76837158203125e-7*a(" "),u[f]<0&&(u[f]+=1);for(var l=0;l>>0},i.fract53=i,i.version="LFib 0.9",i.args=e,i}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),r=0,t=58,n=119,u=178,a=[],f=(0,o.default)();0===e.length&&(e=[+new Date]);for(var l=0;l<256;l++)a[l]=f(" "),a[l]-=4.76837158203125e-7*f(" "),a[l]<0&&(a[l]+=1);for(var i=0;i>>0},c.fract53=c,c.version="LFIB4 0.9",c.args=e,c}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function u(){var e=Array.prototype.slice.call(arguments),r=4294967087,t=4294944443,n=12345,u=12345,a=123,f=12345,l=12345,i=123;0===e.length&&(e=[+new Date]);for(var c=(0,o.default)(),s=0;s>>7)>>>0;return r=t,t=n,n=u,u=a,a=a^a<<6^(e^e<<13)>>>0,(t+t+1)*a>>>0},c=function(){return 2.3283064365386963e-10*i()};return c.uint32=i,c.fract53=function(){return c()+1.1102230246251565e-16*(2097151&i())},c.version="Xorshift03 0.9",c.args=e,c}Object.defineProperty(r,"__esModule",{value:!0}),r.default=u;var a=t(1),o=n(a)}]); 2 | //# sourceMappingURL=prng.min.js.map -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Better Random Numbers for Javascript 2 | 3 | _Note: This is a direct mirror of Johannes Baagøe's wiki on implementations of Randomness in Javascript. [Mr. Baagøe's site](http://baagoe.org/) has largely disappeared from the internet this is a faithful reproduction of it from [Archive.org](https://web.archive.org/web/20120124013936/http://baagoe.org/en/wiki/Better_random_numbers_for_javascript) and other sources. The content is Licensed [Creative Commons Attribution Share Alike](http://creativecommons.org/licenses/by-sa/3.0/)._ 4 | 5 | 6 | 7 | ECMAScript[[1]](#cite_note-0) provides a standard function, `Math.random`, which according to the specifications ([ECMA-262, 3rd edition](http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm), 15.8.2.14) "returns a number value with positive sign, greater than or 8 | equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments." 9 | 10 | This is good enough for its intended use, viz., to provide an easy way for script authors to write cute animations, games, etc. However, if you want to use it for more serious programming, there are several problems. 11 | 12 | Contents 13 | -------- 14 | 15 | - [1 Why Math.random should not be used for serious programming](#why-mathrandom-should-not-be-used-for-serious-programming) 16 | - [1.1 No guarantee of quality](#no-guarantee-of-quality) 17 | - [1.2 No standard way to repeat sequences](#no-standard-way-to-repeat-sequences) 18 | - [1.3 Security](#security) 19 | 20 | - [2 Why it is difficult to write good PRNGs in javascript](#why-it-is-difficult-to-write-good-prngs-in-javascript) 21 | - [2.1 Only 53 significant bits in multiplications](#only-53-significant-bits-in-multiplications) 22 | - [2.2 Limited and inefficient bit operations](#limited-and-inefficient-bit-operations) 23 | 24 | - [3 A collection of better PRNGs](#a-collection-of-better-prngs) 25 | - [3.1 Common interface](#common-interface) 26 | - [3.1.1 Simple usage](#simple-usage) 27 | - [3.1.2 Using methods and properties](#using-methods-and-properties) 28 | 29 | - [3.2 Common implementation details](#common-implementation-details) 30 | - [3.2.1 Mash](#mash) 31 | - [3.2.2 At least two random functions, not just one](#at-least-two-random-functions-not-just-one) 32 | 33 | - [3.3 The generators](#the-generators) 34 | - [3.3.1 MRG32k3a](#mrg32k3a) 35 | - [3.3.2 Xorshift03](#xorshift03) 36 | - [3.3.3 KISS07](#kiss07) 37 | - [3.3.4 LFib](#lfib) 38 | - [3.3.5 LFIB4](#lfib4) 39 | - [3.3.6 Alea](#alea) 40 | - [3.3.7 Kybos](#kybos) 41 | 42 | - [4 License](#license) 43 | - [5 Notes](#notes) 44 | 45 | Why `Math.random` should not be used for serious programming 46 | ------------------------------------------------------------ 47 | 48 | ### No guarantee of quality 49 | 50 | "Using an implementation-dependent algorithm or strategy" means that you don't know how the "random" numbers are made and how "random" they are likely to be, even if you know a lot about [PRNG](http://en.wikipedia.org/wiki/PRNG)s. You have to inspect the code if it is [Open Source](http://en.wikipedia.org/wiki/Open_source), or trust the vendor otherwise. 51 | 52 | ### No standard way to repeat sequences 53 | 54 | In most implementations if not in all, `Math.random`'s generator is silently seeded at startup by some supposedly random value, usually the 55 | present time to the millisecond or whatever other granularity the system provides. 56 | 57 | This means that there is no easy way to repeat a series of pseudo-random numbers in order, e.g., to determine what went wrong in a simulation. It 58 | also means that you cannot give your code to a colleague and expect that she will find what you want to show. Anything that uses `Math.random` is inherently not portable. 59 | 60 | ### Security 61 | 62 | On the other hand, the weakness of many implementations mean that a sequence of outputs of `Math.random` can often be predicted, even when 63 | the intent was that it could not. This may present security risks. `Math.random` should never be used to generate separators in POST 64 | requests[[2]](#cite_note-1), [Version 4 UUIDs](http://en.wikipedia.org/wiki/Universally_Unique_Identifier), [session keys](http://en.wikipedia.org/wiki/Session_key), etc. 65 | 66 | If one wants to do things like that in javascript, `Math.random` is simply not good enough. 67 | 68 | Why it is difficult to write good PRNGs in javascript 69 | ----------------------------------------------------- 70 | 71 | Many families of excellent PRNGs have been conceived for other languages. However, javascript's notion of Numbers make most of them 72 | less than ideal for our purpose. They can be ported (javascript, like any other decent programming language, is [Turing complete](http://en.wikipedia.org/wiki/Turing_completeness)), but at a heavy price in speed. 73 | 74 | ### Only 53 significant bits in multiplications 75 | 76 | Many present algorithms assume exact multiplications on 32-bit unsigned integers, yielding a 64-bit result. Some even multiply 64-bit integers, yielding a 128-bit result. If you want to emulate that in javascript, you have to write multi-precision routines. That is certainly possible, but hardly efficient. 77 | 78 | Even worse, most algorithms based on multiplications assume that overflow results in truncation and discard of the high bits, effectively giving modular arithmetic for free. This works fine on unsigned integers, but javascript Numbers are always "double-precision 64-bit binary format IEEE 754 values". In the case of overflow, it is the **low order** bits that are discarded. 79 | 80 | As an example, let us examine the best-known PRNG of all: the venerable [LCG](http://en.wikipedia.org/wiki/Linear_congruential_generator), on 32-bit unsigned integers. 81 | 82 | If you use [George Marsaglia](http://en.wikipedia.org/wiki/George_Marsaglia)'s "easy to remember" multiplier 69069, everything works nicely: 69069 83 | being less than 221, `x = 69069 * x + 1 >>> 0;` will indeed cycle 84 | through all the possible values. 85 | 86 | But if you choose a bigger multiplier modulo 232 with good figures of merit in the [spectral test](http://random.mat.sbg.ac.at/tests/theory/spectral/), say, 1103515245 which is used in ANSI C and the glibc library, the 87 | result of the multiplication will almost never fit in 53 bits. Low order bits are discarded, which ruins the basis for the algorithm: its 88 | operation modulo 232. 89 | 90 | ### Limited and inefficient bit operations 91 | 92 | Javascript has the usual set of bitwise operations: AND, OR, XOR, shifts, etc. However, they only apply to 32-bit integers, and since javascript Numbers are always floating point, it means that the Numbers must be converted internally to integers before the operation, and back to floats again when it is done. Smart implementations may attempt to optimise, but on all the platforms I have tried, the results remain slow. 93 | 94 | Altogether, precious few of the usual tools are well adapted to javascript. Some ingenuity is required if one wants good performance. 95 | 96 | A collection of better PRNGs 97 | ---------------------------- 98 | 99 | I present several PRNGs that should have much better statistical properties than the built-in `Math.random`. They have been taken from, or inspired by, well-known sources on the subject, and they have been extensively tested. They share a common interface, but the actual algorithms differ, so that one can choose the best for one's platform and needs. They can be downloaded [here](support/Alea-0.9.zip). 100 | 101 | ### Common interface 102 | 103 | We shal take `Alea` as example, but the other PRNGs - `MRG32k3a`, `KISS07`, etc - share the same interface. 104 | 105 | ### Node 106 | 107 | ```javascript 108 | var Alea = require('prng').Alea; 109 | ``` 110 | 111 | ### Browser 112 | 113 | Include one of the prng scripts from the `dist` directory. 114 | 115 | ```javascript 116 | var Alea = prng.Alea; 117 | ``` 118 | 119 | #### Simple usage 120 | 121 | ```javascript 122 | var Alea = ... 123 | 124 | var random = [new] Alea([...]); 125 | ``` 126 | 127 | Calling `Alea` (or any of the others) with `new` is unnecessary, but harmless. The optional arguments may be of any number and nature. 128 | 129 | The call returns a function, `random`, that is functionally equivalent to `Math.random`. 130 | 131 | That is, successive calls of `random()` return Number values with positive sign, greater than or equal to 0 but less than 1, chosen pseudo-randomly with approximately uniform distribution over that range. (Hopefully, with a much better approximation of that [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution_(continuous)).) 132 | 133 | Example 134 | 135 | ```javascript 136 | var random = new Alea("my", 3, "seeds"); 137 | random(); // returns 0.30802189325913787 138 | random(); // returns 0.5190450621303171 139 | random(); // returns 0.43635262292809784 140 | ``` 141 | 142 | Any implementation of ECMAScript should yield exactly those values. 143 | 144 | The internal state of random, and hence the sequence of pseudo-random numbers it returns, is determined by the arguments to `Alea`. Two functions returned by calls to `Alea` with the same argument values will return exactly the same sequence of pseudo-random numbers. String and Number arguments should provide repeatable output across platforms. Object arguments[[3]](#cite_note-2) provide repeatable output on the same platform, but not necessarily on others. 145 | 146 | If you call `Alea()`, that is, with no arguments, a single argument of `+new Date()` is silently assumed. This provides an easy means to provide somewhat unpredictable numbers, like `Math.random` does. 147 | 148 | Example: 149 | 150 | ```javascript 151 | var random = Alea(); 152 | random(); // returns 0.6198398587293923 153 | random(); // returns 0.8385338634252548 154 | random(); // returns 0.3644848605617881 155 | ``` 156 | 157 | Your return values should be completely different. (But see below how you can reproduce mine on your computer.) 158 | 159 | The generated numbers should be "more random" than in most implementations of `Math.random`. Any sequence of any pick of the returned bits should pass any known test, unless where mentioned. (Please send me a mail if you have evidence that this is not true. But please remember that "p's happen": if you repeat any test a million times, some of the results are bound to have very suspicious p-values.) 160 | 161 | The specification of `Math.random` says nothing about the precision of the returned fraction. Here, it is guaranteed that the precision is at least 32 bits. 162 | 163 | Very often, to get the full attainable precision of 53 bits, the main generator has to be called twice, which takes more time. It would be wasteful to insist on doing that systematically, since a 32 bit resolution is enough in most cases. If you really need 53 bits, the function provides a method described below to get them. 164 | 165 | #### Using methods and properties 166 | 167 | Functions being Objects in javascript, the returned function also has two methods, `uint32` and `fract53`, and two properties, `version` and 168 | `args`. 169 | 170 | `uint32` is a function that takes no arguments and returns an unsigned random integer in the range [0, 232[. 171 | 172 | Example: 173 | 174 | ```javascript 175 | var intRandom = Alea("").uint32; 176 | intRandom(); // returns 715789690 177 | intRandom(); // returns 2091287642 178 | intRandom(); // returns 486307 179 | ``` 180 | 181 | Any implementation of ECMAScript should yield exactly those values. 182 | 183 | To obtain an integer in [0, n[, one may simply take the remainder modulo n[[4]](#cite_note-3). With some generators, this is faster than using the default function in `Math.floor(random() * n)` or its clever variants, `random() * n | 0` and `random() * n >>> 0` 184 | 185 | `fract53` is a function that takes no arguments and returns a 53-bit fraction in [0, 1[. It is usually slower than the main function, though. 186 | 187 | Example: 188 | 189 | ```javascript 190 | var rand53 = Alea("").fract53; 191 | rand53(); // returns 0.16665777435687268 192 | rand53(); // returns 0.00011322738143160205 193 | rand53(); // returns 0.17695781631176488 194 | ``` 195 | 196 | Any implementation of ECMAScript should yield exactly those values. 197 | 198 | `version` is a String that indicates the nature and the version of the generator, like 'Alea 0.9'. 199 | 200 | `args` is an Array of the arguments that were given to `Alea`. Thus, if you called it without an argument and it assumed 201 | `+new Date()`, you may recover the time stamp that was used in order to repeat the sequence. 202 | 203 | Example, assuming random is the function created above without arguments (I wrote the example on 22 June 2010 shortly after 7AM in France (summer time), exactly at 2010-06-22T07:01:18.230+02:00): 204 | 205 | ```javascript 206 | var seed = random.args; // seed = 1277182878230 207 | ``` 208 | 209 | This value can be used to reproduce the values in the earlier example that used `Alea()` without arguments: 210 | 211 | ```javascript 212 | random = Alea(1277182878230); 213 | random(); // returns 0.6198398587293923 214 | random(); // returns 0.8385338634252548 215 | random(); // returns 0.3644848605617881 216 | ``` 217 | 218 | Any implementation of ECMAScript should yield exactly those values. 219 | 220 | ### Common implementation details 221 | 222 | Regardless of the differences in their algorithms, internal state, etc, all the generators provided here share a common implementation pattern. 223 | First, the internal state is declared. Then, it is seeded. Then, the main function for the algorithm is presented. Finally, the function-object to be returned is built and returned. 224 | 225 | #### Mash 226 | 227 | [Javascript](support/js/Mash.js) | [C](support/c/mash.h) 228 | 229 | The arguments to `Alea` (and the other provided generators) are always converted into a String which is hashed by the means of a suitable hash 230 | function. 231 | 232 | That hash function, with its initialised internal state, is provided by another function called [Mash](support/js/Mash.js), which must therefore be included in any application that uses any of the provided functions. 233 | 234 | (Alternatively, if you decide to use only one PRNG, you may simply copy Mash into your copy of the relevant file.) 235 | 236 | Each element of the internal state is altered by a hash of each argument. (The hash function preserves its own internal state, so that 237 | each of the alterations is likely to be different.) The exact nature of the alteration depends on the nature of the state element - if it is an integer, the hash is simply added, if it is a single bit, it is XOR-ed, if it is a fraction between 0 and 1, the hash is subtracted and the element is incremented by 1 if it has become negative, etc. 238 | 239 | Finally, whenever the PRNG algorithm places constraints on certain elements of its internal state, the last stage of the seeding process makes sure that these constraints are met. 240 | 241 | #### At least two random functions, not just one 242 | 243 | All the generators provide two functions, the main function which returns 32-bit or 53-bit fractions, and its `uint32` method which returns 32-bit unsigned integers. They also provide the `fract53` method which is guaranteed to return 53-bit fractions; it may or may not be the same as the main function. 244 | 245 | In most algorithms ported from other languages, the algorithm is actually implemented in the `uint32` method. (Operating on 53-bit numbers without ever losing a bit to overflow leaves very few possibilities. 32-bit unsigned integers provide handy bit operations in addition to reducing the problems of unintended overflow; most PRNGs operate on integers for that reason.) The "main" container function calls that integer function and multiplies the result by 232, the `fract53` method calls it twice, once for its 32 high bits and once again for the 21 lowest. 246 | 247 | In the generators of the Lagged Fibonacci family, the PRNG algorithm directly provides the 53-bit fractions. The `uint32` method multiplies by 232 and returns the floored result. The `fract53` method is the same as the main container function. 248 | 249 | In `Alea` and `Kybos`, the main PRNG algorithm provides 32-bit fractions. Both `uint32` and `fract53` are derived. 250 | 251 | ### The generators 252 | 253 | #### MRG32k3a 254 | 255 | [Javascript](support/js/MRG32k3a.js) | [C](support/c/MRG32k3a.c) 256 | 257 | One of [Pierre L'Ecuyer](http://www.iro.umontreal.ca/~lecuyer/)'s Combined Multiple Recursive[[5]](#cite_note-4) PRNGs. It is remarkable for its ingenious use of 53-bit integer arithmetic (originally implemented in C doubles) which makes it very suitable for javascript, as well as for the are in the choice of multipliers and moduli. The period is about 2191, and it passes - of course - L'Ecuyers own [TestU01](http://www.iro.montreal.ca/~simardr/testu01/tu01.html) BigCrush battery of tests. (The [Mersenne Twister](http://en.wikipedia.org/wiki/Mersenne_twister) fails Crush.) 258 | 259 | This is surely the most reputable of all the generators presented here. It has been quite extensively tested and it is widely used. It is copyrighted but free for non-commercial uses. Commercial users must request written permission from Professor L'Ecuyer. 260 | 261 | #### Xorshift03 262 | 263 | [Javascript](support/js/Xorshift03.js) | [C](support/c/Xorshift03.c) 264 | 265 | George Marsaglia's [2003 version](http://groups.google.com/group/comp.lang.c/msg/e3c4ea1169e463ae) of his xorshift family of PRNGs. They are among the fastest available in integer arithmetic, but they become much slower in javascript. Also, most variants tend to fail L'Ecuyer's tests which are rather more stringent than Marsaglia's own. 266 | 267 | This version, however, passes BigCrush, mainly because it contains a final multiplication of two components. Its period is about 2160. 268 | 269 | #### KISS07 270 | 271 | [Javascript](support/js/KISS07.js) | [C](support/c/KISS07.c) 272 | 273 | George Marsaglia's [2007 version](http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5) of his KISS family of PRNGs. 274 | 275 | It is deceptively simple. It merely adds the outputs of three small generators which individually would not have the slightest chance of passing any kind of randomness test. Yet, the result passes BigCrush. The period is about 2121. 276 | 277 | Its xorshift component makes it rather slow, though. It remains a very attractive generator, because its combination of three completely different algorithms with different periods makes it likely that any bias from one of them is blurred by at least one of the two others. 278 | 279 | #### LFib 280 | 281 | [Javascript](support/js/LFib.js) | [C](support/c/LFib.c) 282 | 283 | This is a L(253, 255, 52, -) [lagged Fibonacci](http://en.wikipedia.org/wiki/Lagged_Fibonacci_generator) 284 | generator[[6]](#cite_note-5). The period is very close to 2307. 285 | 286 | It uses subtraction modulo 1 instead of addition in order to retain full 53-bit precision. (One cannot add two 53-bit fractions in [0, 1[ in IEEE 287 | double precision without risking the loss of a bit to overflow. One can subtract them, though, and add 1 if the result is negative - the sign flag serves as a temporary 54-th bit.) 288 | 289 | `LFib` and `LFIB4` are the fastest of the generators presented here to provide full 53-bit resolution, since that is what they provide natively. However, the simple linear dependency between their last bits makes me somewhat reluctant to recommend them wholeheartedly, even though they pass BigCrush. They fail [Michael Niedermayer's tests](http://guru.multimedia.cx/pseudo-random-number-generators/). All of the other PRNGs presented here pass. 290 | 291 | #### LFIB4 292 | 293 | [Javascript](support/js/LFIB4.js) | [C](support/c/LFIB4.c) 294 | 295 | Marsaglia's [LFIB4](http://groups.google.com/group/sci.crypt/msg/eb4ddde782b17051), adapted to subtraction modulo 1 on 53-bit fractions. 296 | 297 | The period is very close to 2308, and its combination of four "taps" instead of two makes it more robust than the usual lagged Fibonacci generators. It also makes it just a little slower, although much faster in javascript than integer-based algorithms. 298 | 299 | #### Alea 300 | 301 | [Javascript](support/js/Alea.js) | [C](support/c/Alea.c) 302 | 303 | This generator implements my variation on Marsaglia's [Multiply-with-carry](http://en.wikipedia.org/wiki/Multiply-with-carry) 304 | theme, adapted to javascript's quaint notion of numbers: the carries are exactly the integer parts of Numbers with exactly 32 bits of fractional part. 305 | 306 | Such generators depend crucially on their multiplier, *a*. It must be less than 221, so that the result of the multiplication fits in 53 bits, and for an array of *n* 32-bit numbers, *a*232*n* − 1 must be a 307 | [safe prime](http://en.wikipedia.org/wiki/Safe_prime). The period is the corresponding [Germain prime](http://en.wikipedia.org/wiki/Sophie_Germain_prime), *a*232*n*\\ −\\ 1 − 1. 308 | 309 | The one presented here uses *n* = 3: just three 32-bit fractions, which means that one may use three rotating variables without walking through an Array. (Table lookup is rather expensive, time-wise.) The period is close to 2116, it passes BigCrush, and it is the fastest javascript PRNG I know that does so. 310 | 311 | I expected such generators with any *n* up to 256 (or even beyond, if one wants monstrously long periods and can find the appropriate multipliers) to be faster than those relying on integer arithmetics, which they are. But they also turn out to be faster than the lagged Fibonacci generators if one does not insist on 53 bits, much to my surprise. 312 | 313 | I therefore propose them as the PRNGs of choice in javascript. I must however confess to the bias induced by more personal involvement in those generators than in the others, which are simple ports in the case of `MRG32k3a`, `Xorshift03` and `KISS07`, and rather straightforward adaptations in the case of the lagged Fibonaccis. 314 | 315 | #### Kybos 316 | 317 | [Javascript](support/js/Kybos.js) | [C](support/c/Kybos.c) 318 | 319 | All the generators presented so far have quite well-defined mathematical properties which have been extensively studied. This gives good reasons to consider them satisfactory, but it also raises a suspicion - aren't they **too** well-behaved? Isn't their elegant mathematical structure by itself a sign that they are not *random*? Except possibly for `KISS07` which combines three quite different ideas, they could be victims of the 320 | Mersenne Twister syndrome - a theoretically wonderful algorithm, with actual proofs of good distribution in all dimensions up to a large number and a huge period, which turns out to fail tests that other, less sophisticated but more robust generators pass easily. 321 | 322 | `Kybos`[[7]](#cite_note-6) combines `Alea` with a variant of the Bays-Durham shuffle), using the ultimate non linear tool: table lookup. The original shuffle rarely improves PRNGs in a noticeable way, but the variant used here, in which the "random" numbers in the lookup table are incremented by those from the original generator instead of being replaced, makes some terrible generators pass very stringent tests. 323 | 324 | The problem is that one cannot say much about the period or other aspects of the resulting numbers. Which may be what one would expect of 325 | anything that is indeed random, but it doesn't make mathematicians happy. 326 | 327 | I mainly propose `Kybos` because it has an extra method, `addNoise`, which allows one to alter the state of the lookup table using true, physical randomness, without changing anything in the state of the `Alea` generator that provides the guarantee of a suitably long period and good distribution. The lookup table essentially serves as an entropy pool. Its size of 256 bits makes it suitable for the generation of 128-bit UUIDs. 328 | 329 | License 330 | ------- 331 | 332 | `MRG32k3a` is [copyrighted](http://www.iro.umontreal.ca/~simardr/testu01/copyright.html) as a part of [TestU01](http://www.iro.umontreal.ca/~simardr/testu01/tu01.html). 333 | 334 | The status of `Xorshift03`, `KISS07` and `LFIB4` is somewhat unclear. The sources are Usenet posts, and one of them explicitly states ["You 335 | are welcome to use one or both of the above"](http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5). It seems unlikely that Professor Marsaglia intended to restrict their use in any way, but on the other hand, I have no indication that he ever formally released them to the public domain. 336 | 337 | My own work is licensed according to the [MIT - Expat license](http://en.wikipedia.org/wiki/MIT_License): 338 | 339 | Copyright (C) 2010 by Johannes Baagøe 340 | 341 | Permission is hereby granted, free of charge, to any person obtaining a copy 342 | of this software and associated documentation files (the "Software"), to deal 343 | in the Software without restriction, including without limitation the rights 344 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 345 | copies of the Software, and to permit persons to whom the Software is 346 | furnished to do so, subject to the following conditions: 347 | 348 | The above copyright notice and this permission notice shall be included in 349 | all copies or substantial portions of the Software. 350 | 351 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 352 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 353 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 354 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 355 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 356 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 357 | THE SOFTWARE. 358 | 359 | Notes 360 | ----- 361 | 362 | 1. [↑](#cite_ref-0) 363 | A note on terminology: I use "javascript" (lowercase, except when 364 | starting a sentence) as a deliberately loose generic term for all 365 | dialects of the language. "JavaScript" (CamelCase) designates 366 | Netscape / Mozilla / Gecko implementations, "JScript" designates 367 | Microsoft's, 368 | "[ECMAScript](http://en.wikipedia.org/wiki/ECMAScript)" 369 | implies conformance with a formally defined version. They are all 370 | javascript, though. 371 | 2. [↑](#cite_ref-1) 372 | [Klein, Amit. 2008. *Temporary user tracking in major browsers and 373 | Cross-domain information leakage and 374 | attacks*](http://www.trusteer.com/sites/default/files/Temporary_User_Tracking_in_Major_Browsers.pdf) 375 | 3. [↑](#cite_ref-2) 376 | The point of using Object arguments to initialise the generators 377 | would be to provide thoroughly unpredictable output. As an extreme 378 | example, one could try `Alea(document)` 379 | or `Alea(this)` in a browser 380 | 4. [↑](#cite_ref-3) 381 | This should only be done in the common case where n is much smaller 382 | than 232 - but the same goes for using the default fraction. 383 | 5. [↑](#cite_ref-4) 384 | [L'Ecuyer, Pierre. 1998. *Good parameters and implementations for 385 | combined multiple recursive random number 386 | generators*](http://www.iro.umontreal.ca/~lecuyer/myftp/papers/combmrg2.ps) 387 | 6. [↑](#cite_ref-5) 388 | I have never understood why people insist on (55, 24), especially 389 | since one often uses an array of 256 "random" numbers anyway, in 390 | order to take advantage of C and similar languages' implicit modulo 391 | 256 arithmetic on `unsigned char` indices. (255, 52) gives a 392 | **much** longer period for absolutely no more effort. 393 | 7. [↑](#cite_ref-6) 394 | [It seems](http://en.wikipedia.org/wiki/Alea_iacta_est) 395 | that when Caesar is supposed to have said "Iacta alea est", he 396 | actually said "Ἀνερρίφθω κύβος". 397 | 398 | -------------------------------------------------------------------------------- /dist/prng.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///dist/prng.min.js","webpack:///webpack/bootstrap cf356f0f46bfd4b37405","webpack:///./support/js/index.js","webpack:///./support/js/Mash.js","webpack:///./support/js/Invwk.js","webpack:///./support/js/Alea.js","webpack:///./support/js/KISS07.js","webpack:///./support/js/Kybos.js","webpack:///./support/js/LFib.js","webpack:///./support/js/LFIB4.js","webpack:///./support/js/MRG32k3a.js","webpack:///./support/js/Xorshift03.js"],"names":["PRNG","modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","_interopRequireDefault","obj","__esModule","default","random","generator","rand","range","from","to","args","Array","prototype","slice","arguments","length","apply","this","Object","assign","_Mash","_Mash2","_Invwk","_Invwk2","_Alea","_Alea2","_KISS","_KISS2","_Kybos","_Kybos2","_LFib","_LFib2","_LFIB","_LFIB2","_MRG32k3a","_MRG32k3a2","_Xorshift","_Xorshift2","Invwk","Mash","Alea","KISS07","Kybos","LFib","LFib4","MRG32k3a","Xorshift03","n","mash","data","toString","i","charCodeAt","h","version","defineProperty","value","max","Date","seed","join","uint32","fract53","s0","s1","s2","t","x","y","z","w","s","k","j","a","r","addNoise","k0","k1","k2","LFIB4","k3","m1","m2","s10","s11","s12","s20","s21","s22","p1","p2","a12","a13n","a21","a23n","v"],"mappings":"AAAA,GAAIA,MACK,SAAUC,GCGnB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDOM,SAASI,EAAQD,EAASH,GAE/B,YAsCA,SAASW,GAAuBC,GAAO,MAAOA,IAAOA,EAAIC,WAAaD,GAAQE,QAASF,GE3ExF,QAASG,GAAOC,GACd,GAAIC,GAAO,IACX,OAAO,YAML,QAASC,GAAMC,EAAMC,GACnB,MAAoB,mBAATD,IAAsC,mBAAPC,GACjCD,EAAOF,IAAS,EACE,mBAATE,IAAsC,mBAAPC,IACtCA,EAAKD,GAAQF,IAASE,EAAQ,EAEhCF,IAXX,GAAII,GAAOC,MAAMC,UAAUC,MAAMjB,KAAKkB,UAetC,OAdAR,GAAOI,EAAKK,OACRV,EAAUW,MAAMC,KAAMP,GACtBL,IAYGa,OAAOC,OAAOZ,EAAOD,IA5BhC,GAAAc,GAAA/B,EAAA,GFmDKgC,EAASrB,EAAuBoB,GElDrCE,EAAAjC,EAAA,GFsDKkC,EAAUvB,EAAuBsB,GErDtCE,EAAAnC,EAAA,GFyDKoC,EAASzB,EAAuBwB,GExDrCE,EAAArC,EAAA,GF4DKsC,EAAS3B,EAAuB0B,GE3DrCE,EAAAvC,EAAA,GF+DKwC,EAAU7B,EAAuB4B,GE9DtCE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IAC/BgB,GAAqB,WAAhBnB,EAAKtC,EAAKyC,IACfiB,GAAqB,WAAhBpB,EAAKtC,EAAKyC,IACfkB,GAAqB,WAAhBrB,EAAKtC,EAAKyC,IACf6C,GAAqB,WAAhBhD,EAAKtC,EAAKyC,IACfmB,GAAqB,WAAhBtB,EAAKtC,EAAKyC,GAEjBH,GAAO,IAEP,IAAIa,GAAS,WACX,GAAIK,IAAKC,EAAKA,IAAM,KAAQ,CAM5B,OALAA,GAAIC,EACJA,EAAIC,EACJA,EAAIC,EACJA,EAAI0B,EACJA,EAAKA,EAAKA,GAAK,GAAO9B,EAAKA,GAAK,MAAS,GAChCE,EAAIA,EAAI,GAAK4B,IAAO,GAG3B5F,EAAS,WACX,MAAkB,wBAAXyD,IAST,OAPAzD,GAAOyD,OAASA,EAChBzD,EAAO0D,QAAU,WACf,MAAO1D,KACmB,wBAAZ,QAAXyD,MAELzD,EAAOkD,QAAU,iBACjBlD,EAAOM,KAAOA,EACPN,EX2pBRc,OAAOqC,eAAe/D,EAAS,cAC7BgE,OAAO,IAEThE,EAAQW,QWzsBe2C,CAHxB,IAAA1B,GAAA/B,EAAA,GXgtBKgC,EAASrB,EAAuBoB","file":"./dist/prng.min.js","sourcesContent":["var PRNG =\n/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tvar _Invwk = __webpack_require__(2);\n\t\n\tvar _Invwk2 = _interopRequireDefault(_Invwk);\n\t\n\tvar _Alea = __webpack_require__(3);\n\t\n\tvar _Alea2 = _interopRequireDefault(_Alea);\n\t\n\tvar _KISS = __webpack_require__(4);\n\t\n\tvar _KISS2 = _interopRequireDefault(_KISS);\n\t\n\tvar _Kybos = __webpack_require__(5);\n\t\n\tvar _Kybos2 = _interopRequireDefault(_Kybos);\n\t\n\tvar _LFib = __webpack_require__(6);\n\t\n\tvar _LFib2 = _interopRequireDefault(_LFib);\n\t\n\tvar _LFIB = __webpack_require__(7);\n\t\n\tvar _LFIB2 = _interopRequireDefault(_LFIB);\n\t\n\tvar _MRG32k3a = __webpack_require__(8);\n\t\n\tvar _MRG32k3a2 = _interopRequireDefault(_MRG32k3a);\n\t\n\tvar _Xorshift = __webpack_require__(9);\n\t\n\tvar _Xorshift2 = _interopRequireDefault(_Xorshift);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\tfunction random(generator) {\n\t var rand = null;\n\t return function () {\n\t var args = Array.prototype.slice.call(arguments);\n\t rand = args.length ? generator.apply(this, args) : generator();\n\t\n\t function range(from, to) {\n\t if (typeof from !== 'undefined' && typeof to === 'undefined') {\n\t return from * rand() | 0;\n\t } else if (typeof from !== 'undefined' && typeof to !== 'undefined') {\n\t return (to - from) * rand() + from | 0;\n\t } else {\n\t return rand();\n\t }\n\t }\n\t\n\t return Object.assign(range, rand);\n\t };\n\t}\n\t\n\tvar rand = random(_Invwk2.default);\n\trand.Invwk = random(_Invwk2.default);\n\trand.Mash = _Mash2.default;\n\trand.Alea = random(_Alea2.default);\n\trand.KISS07 = random(_KISS2.default);\n\trand.Kybos = random(_Kybos2.default);\n\trand.LFib = random(_LFib2.default);\n\trand.LFib4 = random(_LFIB2.default);\n\trand.MRG32k3a = random(_MRG32k3a2.default);\n\trand.Xorshift03 = random(_Xorshift2.default);\n\t\n\tmodule.exports = rand;\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = Mash;\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\t// Johannes Baagøe , 2010\n\tfunction Mash() {\n\t var n = 0xefc8249d;\n\t\n\t var mash = function mash(data) {\n\t data = data.toString();\n\t for (var i = 0; i < data.length; i++) {\n\t n += data.charCodeAt(i);\n\t var h = 0.02519603282416938 * n;\n\t n = h >>> 0;\n\t h -= n;\n\t h *= n;\n\t n = h >>> 0;\n\t h -= n;\n\t n += h * 0x100000000; // 2^32\n\t }\n\t return (n >>> 0) * 2.3283064365386963e-10; // 2^-32\n\t };\n\t\n\t mash.version = 'Mash 0.9';\n\t return mash;\n\t};\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = Invwk;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t//Webkit2's crazy invertible mapping generator\n\t//Based on Andy Hyland's implementation: https://bocoup.com/weblog/random-numbers\n\tfunction Invwk() {\n\t var args = Array.prototype.slice.call(arguments);\n\t var mash = (0, _Mash2.default)();\n\t var max = 0x100000000; // 2 ^ 32\n\t\n\t if (args.length == 0) {\n\t args = [+new Date()];\n\t }\n\t\n\t var seed = mash(args.join('')) * max | 0;\n\t // var seed = (Math.random() * max) | 0;\n\t\n\t var random = function random() {\n\t seed += seed * seed | 5;\n\t // Shift off bits, discarding the sign. Discarding the sign is\n\t // important because OR w/ 5 can give us + or - numbers.\n\t return (seed >>> 32) * 2.3283064365386963e-10;\n\t };\n\t\n\t random.uint32 = function () {\n\t seed += seed * seed | 5;\n\t // Shift off bits, discarding the sign. Discarding the sign is\n\t // important because OR w/ 5 can give us + or - numbers.\n\t return seed >>> 0;\n\t };\n\t random.fract53 = function () {\n\t return random() + (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.version = 'Alea 0.9';\n\t random.args = args;\n\t\n\t return random;\n\t};\n\n/***/ },\n/* 3 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = Alea;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction Alea() {\n\t // Johannes Baagøe , 2010\n\t var args = Array.prototype.slice.call(arguments);\n\t var s0 = 0;\n\t var s1 = 0;\n\t var s2 = 0;\n\t var c = 1;\n\t\n\t if (args.length == 0) {\n\t args = [+new Date()];\n\t }\n\t var mash = (0, _Mash2.default)();\n\t s0 = mash(' ');\n\t s1 = mash(' ');\n\t s2 = mash(' ');\n\t\n\t for (var i = 0; i < args.length; i++) {\n\t s0 -= mash(args[i]);\n\t if (s0 < 0) {\n\t s0 += 1;\n\t }\n\t s1 -= mash(args[i]);\n\t if (s1 < 0) {\n\t s1 += 1;\n\t }\n\t s2 -= mash(args[i]);\n\t if (s2 < 0) {\n\t s2 += 1;\n\t }\n\t }\n\t mash = null;\n\t\n\t var random = function random() {\n\t var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32\n\t s0 = s1;\n\t s1 = s2;\n\t return s2 = t - (c = t | 0);\n\t };\n\t random.uint32 = function () {\n\t return random() * 0x100000000; // 2^32\n\t };\n\t random.fract53 = function () {\n\t return random() + (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.version = 'Alea 0.9';\n\t random.args = args;\n\t return random;\n\t};\n\n/***/ },\n/* 4 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = KISS07;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction KISS07() {\n\t // George Marsaglia, 2007-06-23\n\t //http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5\n\t var args = Array.prototype.slice.call(arguments);\n\t var x = 123456789;\n\t var y = 362436069;\n\t var z = 21288629;\n\t var w = 14921776;\n\t var c = 0;\n\t\n\t if (args.length == 0) {\n\t args = [+new Date()];\n\t }\n\t var mash = (0, _Mash2.default)();\n\t for (var i = 0; i < args.length; i++) {\n\t x ^= mash(args[i]) * 0x100000000; // 2^32\n\t y ^= mash(args[i]) * 0x100000000;\n\t z ^= mash(args[i]) * 0x100000000;\n\t w ^= mash(args[i]) * 0x100000000;\n\t }\n\t if (y === 0) {\n\t y = 1;\n\t }\n\t c ^= z >>> 31;\n\t z &= 0x7fffffff;\n\t if (z % 7559 === 0) {\n\t z++;\n\t }\n\t w &= 0x7fffffff;\n\t if (w % 7559 === 0) {\n\t w++;\n\t }\n\t mash = null;\n\t\n\t var uint32 = function uint32() {\n\t var t;\n\t\n\t x += 545925293;\n\t x >>>= 0;\n\t\n\t y ^= y << 13;\n\t y ^= y >>> 17;\n\t y ^= y << 5;\n\t\n\t t = z + w + c;\n\t z = w;\n\t c = t >>> 31;\n\t w = t & 0x7fffffff;\n\t\n\t return x + y + w >>> 0;\n\t };\n\t\n\t var random = function random() {\n\t return uint32() * 2.3283064365386963e-10; // 2^-32\n\t };\n\t random.uint32 = uint32;\n\t random.fract53 = function () {\n\t return random() + (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.args = args;\n\t random.version = 'KISS07 0.9';\n\t\n\t return random;\n\t};\n\n/***/ },\n/* 5 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = Kybos;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction Kybos() {\n\t // Johannes Baagøe , 2010\n\t var args = Array.prototype.slice.call(arguments);\n\t var s0 = 0;\n\t var s1 = 0;\n\t var s2 = 0;\n\t var c = 1;\n\t var s = [];\n\t var k = 0;\n\t\n\t var mash = (0, _Mash2.default)();\n\t var s0 = mash(' ');\n\t var s1 = mash(' ');\n\t var s2 = mash(' ');\n\t for (var j = 0; j < 8; j++) {\n\t s[j] = mash(' ');\n\t }\n\t\n\t if (args.length == 0) {\n\t args = [+new Date()];\n\t }\n\t for (var i = 0; i < args.length; i++) {\n\t s0 -= mash(args[i]);\n\t if (s0 < 0) {\n\t s0 += 1;\n\t }\n\t s1 -= mash(args[i]);\n\t if (s1 < 0) {\n\t s1 += 1;\n\t }\n\t s2 -= mash(args[i]);\n\t if (s2 < 0) {\n\t s2 += 1;\n\t }\n\t for (var j = 0; j < 8; j++) {\n\t s[j] -= mash(args[i]);\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t }\n\t\n\t var random = function random() {\n\t var a = 2091639;\n\t k = s[k] * 8 | 0;\n\t var r = s[k];\n\t var t = a * s0 + c * 2.3283064365386963e-10; // 2^-32\n\t s0 = s1;\n\t s1 = s2;\n\t s2 = t - (c = t | 0);\n\t s[k] -= s2;\n\t if (s[k] < 0) {\n\t s[k] += 1;\n\t }\n\t return r;\n\t };\n\t random.uint32 = function () {\n\t return random() * 0x100000000; // 2^32\n\t };\n\t random.fract53 = function () {\n\t return random() + (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.addNoise = function () {\n\t for (var i = arguments.length - 1; i >= 0; i--) {\n\t for (j = 0; j < 8; j++) {\n\t s[j] -= mash(arguments[i]);\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t }\n\t };\n\t random.version = 'Kybos 0.9';\n\t random.args = args;\n\t return random;\n\t};\n\n/***/ },\n/* 6 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = LFib;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction LFib() {\n\t // Johannes Baagøe , 2010\n\t var args = Array.prototype.slice.call(arguments);\n\t var k0 = 255,\n\t k1 = 52,\n\t k2 = 0;\n\t var s = [];\n\t\n\t var mash = (0, _Mash2.default)();\n\t if (args.length === 0) {\n\t args = [+new Date()];\n\t }\n\t for (var j = 0; j < 256; j++) {\n\t s[j] = mash(' ');\n\t s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t for (var i = 0; i < args.length; i++) {\n\t for (var j = 0; j < 256; j++) {\n\t s[j] -= mash(args[i]);\n\t s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t }\n\t mash = null;\n\t\n\t var random = function random() {\n\t k0 = k0 + 1 & 255;\n\t k1 = k1 + 1 & 255;\n\t k2 = k2 + 1 & 255;\n\t\n\t var x = s[k0] - s[k1];\n\t if (x < 0.0) {\n\t x += 1.0;\n\t }\n\t x -= s[k2];\n\t if (x < 0.0) {\n\t x += 1.0;\n\t }\n\t return s[k0] = x;\n\t };\n\t\n\t random.uint32 = function () {\n\t return random() * 0x100000000 >>> 0; // 2^32\n\t };\n\t random.fract53 = random;\n\t random.version = 'LFib 0.9';\n\t random.args = args;\n\t\n\t return random;\n\t};\n\n/***/ },\n/* 7 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = LFIB4;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction LFIB4() {\n\t // George Marsaglia's LFIB4,\n\t //http://groups.google.com/group/sci.crypt/msg/eb4ddde782b17051\n\t var args = Array.prototype.slice.call(arguments);\n\t var k0 = 0,\n\t k1 = 58,\n\t k2 = 119,\n\t k3 = 178;\n\t\n\t var s = [];\n\t\n\t var mash = (0, _Mash2.default)();\n\t if (args.length === 0) {\n\t args = [+new Date()];\n\t }\n\t for (var j = 0; j < 256; j++) {\n\t s[j] = mash(' ');\n\t s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t for (var i = 0; i < args.length; i++) {\n\t for (var j = 0; j < 256; j++) {\n\t s[j] -= mash(args[i]);\n\t s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21\n\t if (s[j] < 0) {\n\t s[j] += 1;\n\t }\n\t }\n\t }\n\t mash = null;\n\t\n\t var random = function random() {\n\t var x;\n\t\n\t k0 = k0 + 1 & 255;\n\t k1 = k1 + 1 & 255;\n\t k2 = k2 + 1 & 255;\n\t k3 = k3 + 1 & 255;\n\t\n\t x = s[k0] - s[k1];\n\t if (x < 0) {\n\t x += 1;\n\t }\n\t x -= s[k2];\n\t if (x < 0) {\n\t x += 1;\n\t }\n\t x -= s[k3];\n\t if (x < 0) {\n\t x += 1;\n\t }\n\t\n\t return s[k0] = x;\n\t };\n\t\n\t random.uint32 = function () {\n\t return random() * 0x100000000 >>> 0; // 2^32\n\t };\n\t random.fract53 = random;\n\t random.version = 'LFIB4 0.9';\n\t random.args = args;\n\t\n\t return random;\n\t};\n\n/***/ },\n/* 8 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = MRG32k3a;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction MRG32k3a() {\n\t // Copyright (c) 1998, 2002 Pierre L'Ecuyer, DIRO, Université de Montréal.\n\t // http://www.iro.umontreal.ca/~lecuyer/\n\t var args = Array.prototype.slice.call(arguments);\n\t var m1 = 4294967087;\n\t var m2 = 4294944443;\n\t var s10 = 12345,\n\t s11 = 12345,\n\t s12 = 123,\n\t s20 = 12345,\n\t s21 = 12345,\n\t s22 = 123;\n\t\n\t if (args.length === 0) {\n\t args = [+new Date()];\n\t }\n\t var mash = (0, _Mash2.default)();\n\t for (var i = 0; i < args.length; i++) {\n\t s10 += mash(args[i]) * 0x100000000; // 2 ^ 32\n\t s11 += mash(args[i]) * 0x100000000;\n\t s12 += mash(args[i]) * 0x100000000;\n\t s20 += mash(args[i]) * 0x100000000;\n\t s21 += mash(args[i]) * 0x100000000;\n\t s22 += mash(args[i]) * 0x100000000;\n\t }\n\t s10 %= m1;\n\t s11 %= m1;\n\t s12 %= m1;\n\t s20 %= m2;\n\t s21 %= m2;\n\t s22 %= m2;\n\t mash = null;\n\t\n\t var uint32 = function uint32() {\n\t var m1 = 4294967087;\n\t var m2 = 4294944443;\n\t var a12 = 1403580;\n\t var a13n = 810728;\n\t var a21 = 527612;\n\t var a23n = 1370589;\n\t\n\t var k, p1, p2;\n\t\n\t /* Component 1 */\n\t p1 = a12 * s11 - a13n * s10;\n\t k = p1 / m1 | 0;\n\t p1 -= k * m1;\n\t if (p1 < 0) p1 += m1;\n\t s10 = s11;\n\t s11 = s12;\n\t s12 = p1;\n\t\n\t /* Component 2 */\n\t p2 = a21 * s22 - a23n * s20;\n\t k = p2 / m2 | 0;\n\t p2 -= k * m2;\n\t if (p2 < 0) p2 += m2;\n\t s20 = s21;\n\t s21 = s22;\n\t s22 = p2;\n\t\n\t /* Combination */\n\t if (p1 <= p2) return p1 - p2 + m1;else return p1 - p2;\n\t };\n\t\n\t var random = function random() {\n\t return uint32() * 2.3283064365386963e-10; // 2^-32\n\t };\n\t random.uint32 = uint32;\n\t random.fract53 = function () {\n\t return random() + (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.version = 'MRG32k3a 0.9';\n\t random.args = args;\n\t\n\t return random;\n\t};\n\n/***/ },\n/* 9 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.default = Xorshift03;\n\t\n\tvar _Mash = __webpack_require__(1);\n\t\n\tvar _Mash2 = _interopRequireDefault(_Mash);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\t// From http://baagoe.com/en/RandomMusings/javascript/\n\tfunction Xorshift03() {\n\t // George Marsaglia, 13 May 2003\n\t // http://groups.google.com/group/comp.lang.c/msg/e3c4ea1169e463ae\n\t var args = Array.prototype.slice.call(arguments);\n\t var x = 123456789,\n\t y = 362436069,\n\t z = 521288629,\n\t w = 88675123,\n\t v = 886756453;\n\t\n\t if (args.length == 0) {\n\t args = [+new Date()];\n\t }\n\t var mash = (0, _Mash2.default)();\n\t for (var i = 0; i < args.length; i++) {\n\t x ^= mash(args[i]) * 0x100000000; // 2^32\n\t y ^= mash(args[i]) * 0x100000000;\n\t z ^= mash(args[i]) * 0x100000000;\n\t v ^= mash(args[i]) * 0x100000000;\n\t w ^= mash(args[i]) * 0x100000000;\n\t }\n\t mash = null;\n\t\n\t var uint32 = function uint32() {\n\t var t = (x ^ x >>> 7) >>> 0;\n\t x = y;\n\t y = z;\n\t z = w;\n\t w = v;\n\t v = v ^ v << 6 ^ (t ^ t << 13) >>> 0;\n\t return (y + y + 1) * v >>> 0;\n\t };\n\t\n\t var random = function random() {\n\t return uint32() * 2.3283064365386963e-10; // 2^-32\n\t };\n\t random.uint32 = uint32;\n\t random.fract53 = function () {\n\t return random() + (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\n\t };\n\t random.version = 'Xorshift03 0.9';\n\t random.args = args;\n\t return random;\n\t};\n\n/***/ }\n/******/ ]);\n\n\n// WEBPACK FOOTER //\n// dist/prng.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap cf356f0f46bfd4b37405","import Mash from './Mash';\r\nimport Invwk from './Invwk';\r\nimport Alea from './Alea';\r\nimport KISS07 from './KISS07';\r\nimport Kybos from './Kybos';\r\nimport LFib from './LFib';\r\nimport LFib4 from './LFIB4';\r\nimport MRG32k3a from './MRG32k3a';\r\nimport Xorshift03 from './Xorshift03';\r\n\r\nfunction random(generator) {\r\n var rand = null;\r\n return function () {\r\n var args = Array.prototype.slice.call(arguments);\r\n rand = args.length\r\n ? generator.apply(this, args)\r\n : generator();\r\n\r\n function range(from, to) {\r\n if (typeof from !== 'undefined' && typeof to === 'undefined') {\r\n return from * rand() | 0;\r\n } else if (typeof from !== 'undefined' && typeof to !== 'undefined') {\r\n return ((to - from) * rand() + from) | 0;\r\n } else {\r\n return rand();\r\n }\r\n }\r\n\r\n return Object.assign(range, rand);\r\n }\r\n}\r\n\r\nlet rand = random(Invwk);\r\nrand.Invwk = random(Invwk);\r\nrand.Mash = Mash;\r\nrand.Alea = random(Alea);\r\nrand.KISS07 = random(KISS07);\r\nrand.Kybos = random(Kybos);\r\nrand.LFib = random(LFib);\r\nrand.LFib4 = random(LFib4);\r\nrand.MRG32k3a = random(MRG32k3a);\r\nrand.Xorshift03 = random(Xorshift03);\r\n\r\nmodule.exports = rand;\n\n\n// WEBPACK FOOTER //\n// ./support/js/index.js","// From http://baagoe.com/en/RandomMusings/javascript/\r\n// Johannes Baagøe , 2010\r\nexport default function Mash() {\r\n var n = 0xefc8249d;\r\n\r\n var mash = function (data) {\r\n data = data.toString();\r\n for (var i = 0; i < data.length; i++) {\r\n n += data.charCodeAt(i);\r\n var h = 0.02519603282416938 * n;\r\n n = h >>> 0;\r\n h -= n;\r\n h *= n;\r\n n = h >>> 0;\r\n h -= n;\r\n n += h * 0x100000000; // 2^32\r\n }\r\n return (n >>> 0) * 2.3283064365386963e-10; // 2^-32\r\n };\r\n\r\n mash.version = 'Mash 0.9';\r\n return mash;\r\n\r\n};\r\n\n\n\n// WEBPACK FOOTER //\n// ./support/js/Mash.js","import Mash from './Mash';\r\n\r\n\r\n//Webkit2's crazy invertible mapping generator\r\n//Based on Andy Hyland's implementation: https://bocoup.com/weblog/random-numbers\r\nexport default function Invwk() {\r\n var args = Array.prototype.slice.call(arguments);\r\n var mash = Mash();\r\n var max = 0x100000000; // 2 ^ 32\r\n\r\n if (args.length == 0) {\r\n args = [+new Date];\r\n }\r\n \r\n var seed = (mash(args.join('')) * max) | 0;\r\n // var seed = (Math.random() * max) | 0;\r\n\r\n var random = function () {\r\n seed += (seed * seed) | 5;\r\n // Shift off bits, discarding the sign. Discarding the sign is\r\n // important because OR w/ 5 can give us + or - numbers.\r\n return (seed >>> 32) * 2.3283064365386963e-10;\r\n };\r\n\r\n random.uint32 = function () {\r\n seed += (seed * seed) | 5;\r\n // Shift off bits, discarding the sign. Discarding the sign is\r\n // important because OR w/ 5 can give us + or - numbers.\r\n return (seed >>> 0);\r\n };\r\n random.fract53 = function () {\r\n return random() +\r\n (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.version = 'Alea 0.9';\r\n random.args = args;\r\n\r\n return random;\r\n};\n\n\n// WEBPACK FOOTER //\n// ./support/js/Invwk.js","import Mash from './Mash';\r\n\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function Alea () {\r\n // Johannes Baagøe , 2010\r\n var args = Array.prototype.slice.call(arguments);\r\n var s0 = 0;\r\n var s1 = 0;\r\n var s2 = 0;\r\n var c = 1;\r\n\r\n if (args.length == 0) {\r\n args = [+new Date];\r\n }\r\n var mash = Mash();\r\n s0 = mash(' ');\r\n s1 = mash(' ');\r\n s2 = mash(' ');\r\n\r\n for (var i = 0; i < args.length; i++) {\r\n s0 -= mash(args[i]);\r\n if (s0 < 0) {\r\n s0 += 1;\r\n }\r\n s1 -= mash(args[i]);\r\n if (s1 < 0) {\r\n s1 += 1;\r\n }\r\n s2 -= mash(args[i]);\r\n if (s2 < 0) {\r\n s2 += 1;\r\n }\r\n }\r\n mash = null;\r\n\r\n var random = function () {\r\n var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32\r\n s0 = s1;\r\n s1 = s2;\r\n return s2 = t - (c = t | 0);\r\n };\r\n random.uint32 = function () {\r\n return random() * 0x100000000; // 2^32\r\n };\r\n random.fract53 = function () {\r\n return random() +\r\n (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.version = 'Alea 0.9';\r\n random.args = args;\r\n return random;\r\n\r\n };\r\n\r\n\n\n\n// WEBPACK FOOTER //\n// ./support/js/Alea.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function KISS07() {\r\n // George Marsaglia, 2007-06-23\r\n //http://groups.google.com/group/comp.lang.fortran/msg/6edb8ad6ec5421a5\r\n var args = Array.prototype.slice.call(arguments);\r\n var x = 123456789;\r\n var y = 362436069;\r\n var z = 21288629;\r\n var w = 14921776;\r\n var c = 0;\r\n\r\n if (args.length == 0) {\r\n args = [+new Date];\r\n }\r\n var mash = Mash();\r\n for (var i = 0; i < args.length; i++) {\r\n x ^= mash(args[i]) * 0x100000000; // 2^32\r\n y ^= mash(args[i]) * 0x100000000;\r\n z ^= mash(args[i]) * 0x100000000;\r\n w ^= mash(args[i]) * 0x100000000;\r\n }\r\n if (y === 0) {\r\n y = 1;\r\n }\r\n c ^= z >>> 31;\r\n z &= 0x7fffffff;\r\n if ((z % 7559) === 0) {\r\n z++;\r\n }\r\n w &= 0x7fffffff;\r\n if ((w % 7559) === 0) {\r\n w++;\r\n }\r\n mash = null;\r\n\r\n var uint32 = function () {\r\n var t;\r\n\r\n x += 545925293;\r\n x >>>= 0;\r\n\r\n y ^= y << 13;\r\n y ^= y >>> 17;\r\n y ^= y << 5;\r\n\r\n t = z + w + c;\r\n z = w;\r\n c = t >>> 31;\r\n w = t & 0x7fffffff;\r\n\r\n return x + y + w >>> 0;\r\n };\r\n\r\n var random = function () {\r\n return uint32() * 2.3283064365386963e-10; // 2^-32\r\n };\r\n random.uint32 = uint32;\r\n random.fract53 = function () {\r\n return random() +\r\n (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.args = args;\r\n random.version = 'KISS07 0.9';\r\n\r\n return random;\r\n};\r\n\r\n\n\n\n// WEBPACK FOOTER //\n// ./support/js/KISS07.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function Kybos() {\r\n // Johannes Baagøe , 2010\r\n var args = Array.prototype.slice.call(arguments);\r\n var s0 = 0;\r\n var s1 = 0;\r\n var s2 = 0;\r\n var c = 1;\r\n var s = [];\r\n var k = 0;\r\n\r\n var mash = Mash();\r\n var s0 = mash(' ');\r\n var s1 = mash(' ');\r\n var s2 = mash(' ');\r\n for (var j = 0; j < 8; j++) {\r\n s[j] = mash(' ');\r\n }\r\n\r\n if (args.length == 0) {\r\n args = [+new Date];\r\n }\r\n for (var i = 0; i < args.length; i++) {\r\n s0 -= mash(args[i]);\r\n if (s0 < 0) {\r\n s0 += 1;\r\n }\r\n s1 -= mash(args[i]);\r\n if (s1 < 0) {\r\n s1 += 1;\r\n }\r\n s2 -= mash(args[i]);\r\n if (s2 < 0) {\r\n s2 += 1;\r\n }\r\n for (var j = 0; j < 8; j++) {\r\n s[j] -= mash(args[i]);\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n }\r\n\r\n var random = function () {\r\n var a = 2091639;\r\n k = s[k] * 8 | 0;\r\n var r = s[k];\r\n var t = a * s0 + c * 2.3283064365386963e-10; // 2^-32\r\n s0 = s1;\r\n s1 = s2;\r\n s2 = t - (c = t | 0);\r\n s[k] -= s2;\r\n if (s[k] < 0) {\r\n s[k] += 1;\r\n }\r\n return r;\r\n };\r\n random.uint32 = function () {\r\n return random() * 0x100000000; // 2^32\r\n };\r\n random.fract53 = function () {\r\n return random() +\r\n (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.addNoise = function () {\r\n for (var i = arguments.length - 1; i >= 0; i--) {\r\n for (j = 0; j < 8; j++) {\r\n s[j] -= mash(arguments[i]);\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n }\r\n };\r\n random.version = 'Kybos 0.9';\r\n random.args = args;\r\n return random;\r\n\r\n};\r\n\n\n\n// WEBPACK FOOTER //\n// ./support/js/Kybos.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function LFib() {\r\n // Johannes Baagøe , 2010\r\n var args = Array.prototype.slice.call(arguments);\r\n var k0 = 255,\r\n k1 = 52,\r\n k2 = 0;\r\n var s = [];\r\n\r\n var mash = Mash();\r\n if (args.length === 0) {\r\n args = [+new Date()];\r\n }\r\n for (var j = 0; j < 256; j++) {\r\n s[j] = mash(' ');\r\n s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n for (var i = 0; i < args.length; i++) {\r\n for (var j = 0; j < 256; j++) {\r\n s[j] -= mash(args[i]);\r\n s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n }\r\n mash = null;\r\n\r\n var random = function () {\r\n k0 = (k0 + 1) & 255;\r\n k1 = (k1 + 1) & 255;\r\n k2 = (k2 + 1) & 255;\r\n\r\n var x = s[k0] - s[k1];\r\n if (x < 0.0) {\r\n x += 1.0;\r\n }\r\n x -= s[k2];\r\n if (x < 0.0) {\r\n x += 1.0;\r\n }\r\n return s[k0] = x;\r\n }\r\n\r\n random.uint32 = function () {\r\n return random() * 0x100000000 >>> 0; // 2^32\r\n };\r\n random.fract53 = random;\r\n random.version = 'LFib 0.9';\r\n random.args = args;\r\n\r\n return random;\r\n};\n\n\n// WEBPACK FOOTER //\n// ./support/js/LFib.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function LFIB4() {\r\n // George Marsaglia's LFIB4,\r\n //http://groups.google.com/group/sci.crypt/msg/eb4ddde782b17051\r\n var args = Array.prototype.slice.call(arguments);\r\n var k0 = 0,\r\n k1 = 58,\r\n k2 = 119,\r\n k3 = 178;\r\n\r\n var s = [];\r\n\r\n var mash = Mash();\r\n if (args.length === 0) {\r\n args = [+new Date()];\r\n }\r\n for (var j = 0; j < 256; j++) {\r\n s[j] = mash(' ');\r\n s[j] -= mash(' ') * 4.76837158203125e-7; // 2^-21\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n for (var i = 0; i < args.length; i++) {\r\n for (var j = 0; j < 256; j++) {\r\n s[j] -= mash(args[i]);\r\n s[j] -= mash(args[i]) * 4.76837158203125e-7; // 2^-21\r\n if (s[j] < 0) {\r\n s[j] += 1;\r\n }\r\n }\r\n }\r\n mash = null;\r\n\r\n var random = function () {\r\n var x;\r\n\r\n k0 = (k0 + 1) & 255;\r\n k1 = (k1 + 1) & 255;\r\n k2 = (k2 + 1) & 255;\r\n k3 = (k3 + 1) & 255;\r\n\r\n x = s[k0] - s[k1];\r\n if (x < 0) {\r\n x += 1;\r\n }\r\n x -= s[k2];\r\n if (x < 0) {\r\n x += 1;\r\n }\r\n x -= s[k3];\r\n if (x < 0) {\r\n x += 1;\r\n }\r\n\r\n return s[k0] = x;\r\n }\r\n\r\n random.uint32 = function () {\r\n return random() * 0x100000000 >>> 0; // 2^32\r\n };\r\n random.fract53 = random;\r\n random.version = 'LFIB4 0.9';\r\n random.args = args;\r\n\r\n return random;\r\n};\n\n\n// WEBPACK FOOTER //\n// ./support/js/LFIB4.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function MRG32k3a() {\r\n // Copyright (c) 1998, 2002 Pierre L'Ecuyer, DIRO, Université de Montréal.\r\n // http://www.iro.umontreal.ca/~lecuyer/\r\n var args = Array.prototype.slice.call(arguments);\r\n var m1 = 4294967087;\r\n var m2 = 4294944443;\r\n var s10 = 12345,\r\n s11 = 12345,\r\n s12 = 123,\r\n s20 = 12345,\r\n s21 = 12345,\r\n s22 = 123;\r\n\r\n if (args.length === 0) {\r\n args = [+new Date()];\r\n }\r\n var mash = Mash();\r\n for (var i = 0; i < args.length; i++) {\r\n s10 += mash(args[i]) * 0x100000000; // 2 ^ 32\r\n s11 += mash(args[i]) * 0x100000000;\r\n s12 += mash(args[i]) * 0x100000000;\r\n s20 += mash(args[i]) * 0x100000000;\r\n s21 += mash(args[i]) * 0x100000000;\r\n s22 += mash(args[i]) * 0x100000000;\r\n }\r\n s10 %= m1;\r\n s11 %= m1;\r\n s12 %= m1;\r\n s20 %= m2;\r\n s21 %= m2;\r\n s22 %= m2;\r\n mash = null;\r\n\r\n var uint32 = function () {\r\n var m1 = 4294967087;\r\n var m2 = 4294944443;\r\n var a12 = 1403580;\r\n var a13n = 810728;\r\n var a21 = 527612;\r\n var a23n = 1370589;\r\n\r\n var k, p1, p2;\r\n\r\n /* Component 1 */\r\n p1 = a12 * s11 - a13n * s10;\r\n k = p1 / m1 | 0;\r\n p1 -= k * m1;\r\n if (p1 < 0) p1 += m1;\r\n s10 = s11;\r\n s11 = s12;\r\n s12 = p1;\r\n\r\n /* Component 2 */\r\n p2 = a21 * s22 - a23n * s20;\r\n k = p2 / m2 | 0;\r\n p2 -= k * m2;\r\n if (p2 < 0) p2 += m2;\r\n s20 = s21;\r\n s21 = s22;\r\n s22 = p2;\r\n\r\n /* Combination */\r\n if (p1 <= p2) return p1 - p2 + m1;\r\n else return p1 - p2;\r\n };\r\n\r\n var random = function () {\r\n return uint32() * 2.3283064365386963e-10; // 2^-32\r\n };\r\n random.uint32 = uint32;\r\n random.fract53 = function () {\r\n return random() +\r\n (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.version = 'MRG32k3a 0.9';\r\n random.args = args;\r\n\r\n return random;\r\n};\n\n\n// WEBPACK FOOTER //\n// ./support/js/MRG32k3a.js","import Mash from './Mash';\r\n\r\n// From http://baagoe.com/en/RandomMusings/javascript/\r\nexport default function Xorshift03() {\r\n // George Marsaglia, 13 May 2003\r\n // http://groups.google.com/group/comp.lang.c/msg/e3c4ea1169e463ae\r\n var args = Array.prototype.slice.call(arguments);\r\n var x = 123456789,\r\n y = 362436069,\r\n z = 521288629,\r\n w = 88675123,\r\n v = 886756453;\r\n\r\n if (args.length == 0) {\r\n args = [+new Date];\r\n }\r\n var mash = Mash();\r\n for (var i = 0; i < args.length; i++) {\r\n x ^= mash(args[i]) * 0x100000000; // 2^32\r\n y ^= mash(args[i]) * 0x100000000;\r\n z ^= mash(args[i]) * 0x100000000;\r\n v ^= mash(args[i]) * 0x100000000;\r\n w ^= mash(args[i]) * 0x100000000;\r\n }\r\n mash = null;\r\n\r\n var uint32 = function () {\r\n var t = (x ^ (x >>> 7)) >>> 0;\r\n x = y;\r\n y = z;\r\n z = w;\r\n w = v;\r\n v = (v ^ (v << 6)) ^ (t ^ (t << 13)) >>> 0;\r\n return ((y + y + 1) * v) >>> 0;\r\n }\r\n\r\n var random = function () {\r\n return uint32() * 2.3283064365386963e-10; // 2^-32\r\n };\r\n random.uint32 = uint32;\r\n random.fract53 = function () {\r\n return random() +\r\n (uint32() & 0x1fffff) * 1.1102230246251565e-16; // 2^-53\r\n };\r\n random.version = 'Xorshift03 0.9';\r\n random.args = args;\r\n return random;\r\n\r\n};\n\n\n// WEBPACK FOOTER //\n// ./support/js/Xorshift03.js"],"sourceRoot":""} --------------------------------------------------------------------------------