first commit
This commit is contained in:
30
build/node_modules/seedrandom/test/altprng.html
generated
vendored
Normal file
30
build/node_modules/seedrandom/test/altprng.html
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="../lib/xor4096.min.js"></script>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script>
|
||||
QUnit.module("Alternative PRNG Test");
|
||||
|
||||
QUnit.test("Verify that we can use xor4096", function(assert) {
|
||||
// Use xor4096 for Richard Brent's xorgens-4096 algorithm.
|
||||
var xorgen = new xor4096('hello.');
|
||||
|
||||
// By default provides 32 bits of randomness in a float.
|
||||
assert.equal(xorgen(), 0.9798525865189731);
|
||||
|
||||
// Use "double" to get 56 bits of randomness.
|
||||
assert.equal(xorgen.double(), 0.03583478477375346);
|
||||
|
||||
// Use "int32" to get a 32 bit (signed) integer.
|
||||
assert.equal(xorgen.int32(), 1341429986);
|
||||
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
|
||||
|
||||
46
build/node_modules/seedrandom/test/autoseed.html
generated
vendored
Normal file
46
build/node_modules/seedrandom/test/autoseed.html
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script src="../seedrandom.js"></script>
|
||||
<script>
|
||||
QUnit.module("Simple Test");
|
||||
|
||||
QUnit.test("Check that we can reproduce a seed", function(assert) {
|
||||
var seed;
|
||||
var time = new Date().getTime();
|
||||
var seediter = 50;
|
||||
for (var k = 0; k < seediter; ++k) {
|
||||
seed = Math.seedrandom();
|
||||
}
|
||||
var seedtime = (new Date().getTime() - time) / seediter;
|
||||
|
||||
time = new Date().getTime();
|
||||
var vals = [];
|
||||
var iters = 1000;
|
||||
var j;
|
||||
for (j = 0; j < iters; ++j) {
|
||||
var saw = Math.random();
|
||||
vals.push(saw);
|
||||
}
|
||||
time = new Date().getTime() - time;
|
||||
var errors = 0;
|
||||
Math.seedrandom(seed);
|
||||
for (j = 0; j < vals.length; ++j) {
|
||||
var saw = vals[j];
|
||||
var got = Math.random();
|
||||
assert.equal(saw, got, saw + " vs " + got);
|
||||
}
|
||||
|
||||
assert.ok(true, '' +
|
||||
'Seeding took ' + seedtime + ' ms per seedrandom' +
|
||||
' in ' + time + ' ms for ' + iters +
|
||||
' calls, ' + (time / iters) + ' ms per random()' + '');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
45
build/node_modules/seedrandom/test/bitgen.js
generated
vendored
Executable file
45
build/node_modules/seedrandom/test/bitgen.js
generated
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
var seedrandom = require('../seedrandom');
|
||||
|
||||
// process.on('SIGPIPE', process.exit);
|
||||
function epipeBomb(stream, callback) {
|
||||
if (stream == null) stream = process.stdout;
|
||||
if (callback == null) callback = process.exit;
|
||||
|
||||
function epipeFilter(err) {
|
||||
if (err.code === 'EPIPE') return callback();
|
||||
|
||||
// If there's more than one error handler (ie, us),
|
||||
// then the error won't be bubbled up anyway
|
||||
if (stream.listeners('error').length <= 1) {
|
||||
stream.removeAllListeners(); // Pretend we were never here
|
||||
stream.emit('error', err); // Then emit as if we were never here
|
||||
stream.on('error', epipeFilter);// Reattach, ready for the next error!
|
||||
}
|
||||
}
|
||||
|
||||
stream.on('error', epipeFilter);
|
||||
}
|
||||
|
||||
epipeBomb();
|
||||
|
||||
var bufsize = 1024 * 256,
|
||||
buf = new Buffer(bufsize * 4),
|
||||
prng = seedrandom(0),
|
||||
count = parseInt(process.argv[2]) || Infinity;
|
||||
function dowrite() {
|
||||
while (count > 0) {
|
||||
for (var j = 0; j < bufsize; ++j) {
|
||||
buf.writeUInt32BE(Math.floor(
|
||||
prng() * 256 * 256 * 256 * 256
|
||||
), j * 4);
|
||||
}
|
||||
count -= bufsize * 32;
|
||||
if (!process.stdout.write(buf)) {
|
||||
process.stdout.once('drain', function() { setTimeout(dowrite, 0) });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dowrite();
|
||||
23
build/node_modules/seedrandom/test/browserified.html
generated
vendored
Normal file
23
build/node_modules/seedrandom/test/browserified.html
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script>
|
||||
function describe(name, fn) {
|
||||
QUnit.module(name);
|
||||
fn();
|
||||
}
|
||||
function it(desc, fn) {
|
||||
QUnit.test(desc, function(a) {
|
||||
fn();
|
||||
a.ok(true);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script src="browserified.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
489
build/node_modules/seedrandom/test/browserified.js
generated
vendored
Normal file
489
build/node_modules/seedrandom/test/browserified.js
generated
vendored
Normal file
@@ -0,0 +1,489 @@
|
||||
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
arguments[4][1][0].apply(exports,arguments)
|
||||
},{"dup":1}],3:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2014 David Bau.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
(function (pool, math) {
|
||||
//
|
||||
// The following constants are related to IEEE 754 limits.
|
||||
//
|
||||
var global = this,
|
||||
width = 256, // each RC4 output is 0 <= x < 256
|
||||
chunks = 6, // at least six RC4 outputs for each double
|
||||
digits = 52, // there are 52 significant digits in a double
|
||||
rngname = 'random', // rngname: name for Math.random and Math.seedrandom
|
||||
startdenom = math.pow(width, chunks),
|
||||
significance = math.pow(2, digits),
|
||||
overflow = significance * 2,
|
||||
mask = width - 1,
|
||||
nodecrypto; // node.js crypto module, initialized at the bottom.
|
||||
|
||||
//
|
||||
// seedrandom()
|
||||
// This is the seedrandom function described above.
|
||||
//
|
||||
function seedrandom(seed, options, callback) {
|
||||
var key = [];
|
||||
options = (options == true) ? { entropy: true } : (options || {});
|
||||
|
||||
// Flatten the seed string or build one from local entropy if needed.
|
||||
var shortseed = mixkey(flatten(
|
||||
options.entropy ? [seed, tostring(pool)] :
|
||||
(seed == null) ? autoseed() : seed, 3), key);
|
||||
|
||||
// Use the seed to initialize an ARC4 generator.
|
||||
var arc4 = new ARC4(key);
|
||||
|
||||
// This function returns a random double in [0, 1) that contains
|
||||
// randomness in every bit of the mantissa of the IEEE 754 value.
|
||||
var prng = function() {
|
||||
var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
|
||||
d = startdenom, // and denominator d = 2 ^ 48.
|
||||
x = 0; // and no 'extra last byte'.
|
||||
while (n < significance) { // Fill up all significant digits by
|
||||
n = (n + x) * width; // shifting numerator and
|
||||
d *= width; // denominator and generating a
|
||||
x = arc4.g(1); // new least-significant-byte.
|
||||
}
|
||||
while (n >= overflow) { // To avoid rounding up, before adding
|
||||
n /= 2; // last byte, shift everything
|
||||
d /= 2; // right using integer math until
|
||||
x >>>= 1; // we have exactly the desired bits.
|
||||
}
|
||||
return (n + x) / d; // Form the number within [0, 1).
|
||||
};
|
||||
|
||||
prng.int32 = function() { return arc4.g(4) | 0; }
|
||||
prng.quick = function() { return arc4.g(4) / 0x100000000; }
|
||||
prng.double = prng;
|
||||
|
||||
// Mix the randomness into accumulated entropy.
|
||||
mixkey(tostring(arc4.S), pool);
|
||||
|
||||
// Calling convention: what to return as a function of prng, seed, is_math.
|
||||
return (options.pass || callback ||
|
||||
function(prng, seed, is_math_call, state) {
|
||||
if (state) {
|
||||
// Load the arc4 state from the given state if it has an S array.
|
||||
if (state.S) { copy(state, arc4); }
|
||||
// Only provide the .state method if requested via options.state.
|
||||
prng.state = function() { return copy(arc4, {}); }
|
||||
}
|
||||
|
||||
// If called as a method of Math (Math.seedrandom()), mutate
|
||||
// Math.random because that is how seedrandom.js has worked since v1.0.
|
||||
if (is_math_call) { math[rngname] = prng; return seed; }
|
||||
|
||||
// Otherwise, it is a newer calling convention, so return the
|
||||
// prng directly.
|
||||
else return prng;
|
||||
})(
|
||||
prng,
|
||||
shortseed,
|
||||
'global' in options ? options.global : (this == math),
|
||||
options.state);
|
||||
}
|
||||
math['seed' + rngname] = seedrandom;
|
||||
|
||||
//
|
||||
// ARC4
|
||||
//
|
||||
// An ARC4 implementation. The constructor takes a key in the form of
|
||||
// an array of at most (width) integers that should be 0 <= x < (width).
|
||||
//
|
||||
// The g(count) method returns a pseudorandom integer that concatenates
|
||||
// the next (count) outputs from ARC4. Its return value is a number x
|
||||
// that is in the range 0 <= x < (width ^ count).
|
||||
//
|
||||
function ARC4(key) {
|
||||
var t, keylen = key.length,
|
||||
me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
|
||||
|
||||
// The empty key [] is treated as [0].
|
||||
if (!keylen) { key = [keylen++]; }
|
||||
|
||||
// Set up S using the standard key scheduling algorithm.
|
||||
while (i < width) {
|
||||
s[i] = i++;
|
||||
}
|
||||
for (i = 0; i < width; i++) {
|
||||
s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
|
||||
s[j] = t;
|
||||
}
|
||||
|
||||
// The "g" method returns the next (count) outputs as one number.
|
||||
(me.g = function(count) {
|
||||
// Using instance members instead of closure state nearly doubles speed.
|
||||
var t, r = 0,
|
||||
i = me.i, j = me.j, s = me.S;
|
||||
while (count--) {
|
||||
t = s[i = mask & (i + 1)];
|
||||
r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
|
||||
}
|
||||
me.i = i; me.j = j;
|
||||
return r;
|
||||
// For robust unpredictability, the function call below automatically
|
||||
// discards an initial batch of values. This is called RC4-drop[256].
|
||||
// See http://google.com/search?q=rsa+fluhrer+response&btnI
|
||||
})(width);
|
||||
}
|
||||
|
||||
//
|
||||
// copy()
|
||||
// Copies internal state of ARC4 to or from a plain object.
|
||||
//
|
||||
function copy(f, t) {
|
||||
t.i = f.i;
|
||||
t.j = f.j;
|
||||
t.S = f.S.slice();
|
||||
return t;
|
||||
};
|
||||
|
||||
//
|
||||
// flatten()
|
||||
// Converts an object tree to nested arrays of strings.
|
||||
//
|
||||
function flatten(obj, depth) {
|
||||
var result = [], typ = (typeof obj), prop;
|
||||
if (depth && typ == 'object') {
|
||||
for (prop in obj) {
|
||||
try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
|
||||
}
|
||||
}
|
||||
return (result.length ? result : typ == 'string' ? obj : obj + '\0');
|
||||
}
|
||||
|
||||
//
|
||||
// mixkey()
|
||||
// Mixes a string seed into a key that is an array of integers, and
|
||||
// returns a shortened string seed that is equivalent to the result key.
|
||||
//
|
||||
function mixkey(seed, key) {
|
||||
var stringseed = seed + '', smear, j = 0;
|
||||
while (j < stringseed.length) {
|
||||
key[mask & j] =
|
||||
mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
|
||||
}
|
||||
return tostring(key);
|
||||
}
|
||||
|
||||
//
|
||||
// autoseed()
|
||||
// Returns an object for autoseeding, using window.crypto and Node crypto
|
||||
// module if available.
|
||||
//
|
||||
function autoseed() {
|
||||
try {
|
||||
var out;
|
||||
if (nodecrypto && (out = nodecrypto.randomBytes)) {
|
||||
// The use of 'out' to remember randomBytes makes tight minified code.
|
||||
out = out(width);
|
||||
} else {
|
||||
out = new Uint8Array(width);
|
||||
(global.crypto || global.msCrypto).getRandomValues(out);
|
||||
}
|
||||
return tostring(out);
|
||||
} catch (e) {
|
||||
var browser = global.navigator,
|
||||
plugins = browser && browser.plugins;
|
||||
return [+new Date, global, plugins, global.screen, tostring(pool)];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// tostring()
|
||||
// Converts an array of charcodes to a string
|
||||
//
|
||||
function tostring(a) {
|
||||
return String.fromCharCode.apply(0, a);
|
||||
}
|
||||
|
||||
//
|
||||
// When seedrandom.js is loaded, we immediately mix a few bits
|
||||
// from the built-in RNG into the entropy pool. Because we do
|
||||
// not want to interfere with deterministic PRNG state later,
|
||||
// seedrandom will not call math.random on its own again after
|
||||
// initialization.
|
||||
//
|
||||
mixkey(math.random(), pool);
|
||||
|
||||
//
|
||||
// Nodejs and AMD support: export the implementation as a module using
|
||||
// either convention.
|
||||
//
|
||||
if ((typeof module) == 'object' && module.exports) {
|
||||
module.exports = seedrandom;
|
||||
// When in node.js, try using crypto package for autoseeding.
|
||||
try {
|
||||
nodecrypto = require('crypto');
|
||||
} catch (ex) {}
|
||||
} else if ((typeof define) == 'function' && define.amd) {
|
||||
define(function() { return seedrandom; });
|
||||
}
|
||||
|
||||
// End anonymous scope, and pass initial values.
|
||||
})(
|
||||
[], // pool: entropy pool starts empty
|
||||
Math // math: package containing random, pow, and seedrandom
|
||||
);
|
||||
|
||||
},{"crypto":1}],4:[function(require,module,exports){
|
||||
(function (__dirname){
|
||||
var assert = require("assert");
|
||||
var seedrandom = require("../seedrandom");
|
||||
var requirejs = require("requirejs");
|
||||
|
||||
// Stub out requirejs if in the browser via browserify.
|
||||
if (!requirejs.config) {
|
||||
requirejs = require;
|
||||
} else {
|
||||
requirejs.config({
|
||||
baseUrl: __dirname
|
||||
});
|
||||
}
|
||||
|
||||
describe("Nodejs API Test", function() {
|
||||
|
||||
it('should pass basic tests.', function() {
|
||||
var original = Math.random,
|
||||
result, r, xprng, obj, as2, as3, autoseed1, myrng,
|
||||
firstprng, secondprng, thirdprng, rng;
|
||||
|
||||
result = Math.seedrandom('hello.');
|
||||
firstprng = Math.random;
|
||||
assert.ok(original !== firstprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
|
||||
// should be able to autoseed
|
||||
result = Math.seedrandom();
|
||||
secondprng = Math.random;
|
||||
assert.ok(original !== secondprng, "Should change Math.random.");
|
||||
assert.ok(firstprng !== secondprng, "Should change Math.random.");
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.ok(r > 0, "Should be posititive.");
|
||||
assert.ok(r < 1, "Should be less than 1.");
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.3752569768646784, "Should not be 'hello.'#2");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
autoseed1 = r;
|
||||
|
||||
// should be able to add entropy.
|
||||
result = Math.seedrandom('added entropy.', { entropy:true });
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
thirdprng = Math.random;
|
||||
assert.ok(thirdprng !== secondprng, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Reset to original Math.random.
|
||||
Math.random = original;
|
||||
// should be able to use new Math.seedrandom('hello.')
|
||||
myrng = new Math.seedrandom('hello.');
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// should be able to use seedrandom('hello.')"
|
||||
rng = seedrandom('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
|
||||
// Global PRNG: set Math.random.
|
||||
// should be able to use seedrandom('hello.', { global: true })
|
||||
result = seedrandom('hello.', { global: true });
|
||||
assert.equal(result, 'hello.', "Should return short seed.");
|
||||
assert.ok(original != Math.random, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// Autoseeded non-global
|
||||
Math.random = original;
|
||||
// should be able to use seedrandom()
|
||||
result = seedrandom();
|
||||
assert.equal(typeof(result), 'function', "Should return function.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
|
||||
// Mixing accumulated entropy.
|
||||
// should be able to use seedrandom('added entropy.', { entropy: true })
|
||||
rng = seedrandom('added entropy.', { entropy: true });
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Legacy calling convention for mixing accumulated entropy.
|
||||
// should be able to use seedrandom('added entropy.', true)
|
||||
rng = seedrandom('added entropy.', true);
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// The pass option
|
||||
// should be able to use Math.seedrandom(null, { pass: ...
|
||||
obj = Math.seedrandom(null, { pass: function(prng, seed) {
|
||||
return { random: prng, seed: seed };
|
||||
}});
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== obj.random, "Should be different from Math.random.");
|
||||
assert.equal(typeof(obj.random), 'function', "Should return a PRNG function.");
|
||||
assert.equal(typeof(obj.seed), 'string', "Should return a seed.");
|
||||
as2 = obj.random();
|
||||
assert.ok(as2 != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
rng = seedrandom(obj.seed);
|
||||
as3 = rng();
|
||||
assert.equal(as2, as3, "Should be reproducible when using the seed.");
|
||||
|
||||
// Exercise pass again, with explicit seed and global
|
||||
// should be able to use Math.seedrandom('hello.', { pass: ...
|
||||
result = Math.seedrandom('hello.', {
|
||||
global: 'abc',
|
||||
pass: function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert");
|
||||
assert.equal(global, 'abc', "Callback arg #3 passed through.");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'def';
|
||||
}});
|
||||
assert.equal(result, 'def', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Legacy third argument callback argument:
|
||||
// should be able to use Math.seedrandom('hello.', { global: 50 }, callback)
|
||||
result = Math.seedrandom('hello.', { global: 50 },
|
||||
function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert");
|
||||
assert.equal(global, 50, "Callback arg #3 assert");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'zzz';
|
||||
});
|
||||
assert.equal(result, 'zzz', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Global: false.
|
||||
// should be able to use new Math.seedrandom('hello.', {global: false})
|
||||
myrng = new Math.seedrandom('hello.', {global:false});
|
||||
assert.equal(typeof(myrng), 'function', "Should return a PRNG funciton.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// options = {} when a method of Math.
|
||||
// should be able to use Math.seedrandom('hello.', {})
|
||||
result = Math.seedrandom('hello.');
|
||||
xprng = Math.random;
|
||||
assert.ok(original !== xprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
Math.random = original;
|
||||
|
||||
// options = {} when not a method of Math
|
||||
// should be able to use seedrandom('hello.', {})
|
||||
rng = seedrandom('hello.', {});
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
});
|
||||
|
||||
it('should support state api.', function() {
|
||||
// Verify that there is no state method
|
||||
var dummy = seedrandom('hello');
|
||||
var unexpected = -1;
|
||||
var expected = -1;
|
||||
try {
|
||||
unexpected = dummy.state();
|
||||
} catch(e) {
|
||||
expected = 1;
|
||||
}
|
||||
assert.equal(unexpected, -1);
|
||||
assert.equal(expected, 1);
|
||||
var count = 0;
|
||||
for (var x in dummy) {
|
||||
if (x == 'state') count += 1;
|
||||
}
|
||||
assert.equal(count, 0);
|
||||
|
||||
// Verify that a state method can be added
|
||||
var saveable = seedrandom("secret-seed", {state: true});
|
||||
var ordinary = seedrandom("secret-seed");
|
||||
for (var j = 0; j < 1e2; ++j) {
|
||||
assert.equal(ordinary(), saveable());
|
||||
}
|
||||
var virgin = seedrandom("secret-seed");
|
||||
var saved = saveable.state();
|
||||
var replica = seedrandom("", {state: saved});
|
||||
for (var j = 0; j < 1e2; ++j) {
|
||||
var r = replica();
|
||||
assert.equal(r, saveable());
|
||||
assert.equal(r, ordinary());
|
||||
assert.ok(r != virgin());
|
||||
}
|
||||
});
|
||||
|
||||
it('should support requirejs in node.', function() {
|
||||
var original = Math.random;
|
||||
var rsr = requirejs('../seedrandom');
|
||||
var rng = rsr('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
var r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
});
|
||||
|
||||
// End of test.
|
||||
|
||||
});
|
||||
|
||||
}).call(this,"/test")
|
||||
},{"../seedrandom":3,"assert":"assert","requirejs":2}],"assert":[function(require,module,exports){
|
||||
// Use QUnit.assert to mimic node.assert.
|
||||
|
||||
module.exports = QUnit.assert;
|
||||
|
||||
},{}]},{},[4]);
|
||||
57
build/node_modules/seedrandom/test/cryptotest.js
generated
vendored
Normal file
57
build/node_modules/seedrandom/test/cryptotest.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
var proxyquire = require('proxyquire');
|
||||
var assert = require("assert");
|
||||
var Module = require("module");
|
||||
|
||||
describe("Crypto API Test", function() {
|
||||
|
||||
var crypto_stub = {};
|
||||
var original = Math.random;
|
||||
var rng, r;
|
||||
|
||||
// Load seedrandom in absence of any crypto package.
|
||||
it("should be able to seed without crypto", function() {
|
||||
var noncrypto_sr = proxyquire('../seedrandom', { crypto: null });
|
||||
rng = noncrypto_sr('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert(original === Math.random, "Should not change Math.random.");
|
||||
assert(original !== rng, "PRNG should not be Math.random.");
|
||||
var noncrypto_sr = proxyquire('../seedrandom', { crypto: null });
|
||||
result = noncrypto_sr();
|
||||
assert.equal(typeof(result), 'function', "Should return function.");
|
||||
assert(original === Math.random, "Should not change Math.random.");
|
||||
r = result();
|
||||
assert(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
assert(r != 0.23144008215179881, "Should not be '\\0'#1");
|
||||
assert(r != 0.7220382488550928, "Should not be '\\1'#1");
|
||||
// Recache original seedrandom.
|
||||
proxyquire('../seedrandom', {});
|
||||
});
|
||||
|
||||
// Load seedrandom with zeroed-out crypto package.
|
||||
it("should be able to seed ('hello.') with zero crypto", function() {
|
||||
var zerocrypto_sr = proxyquire('../seedrandom', {
|
||||
crypto: { randomBytes: function(n) {
|
||||
result = []; while (n-- > 0) { result.push(1); } return result; } }
|
||||
});
|
||||
rng = zerocrypto_sr('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454 , "Should be 'hello.'#1");
|
||||
assert(original === Math.random, "Should not change Math.random.");
|
||||
assert(original !== rng, "PRNG should not be Math.random.");
|
||||
rng = zerocrypto_sr();
|
||||
assert.equal(typeof(rng), 'function', "Should return function.");
|
||||
assert(original === Math.random, "Should not change Math.random.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.7220382488550928, "Should be '\\1'#1");
|
||||
r = rng();
|
||||
assert.equal(r, 0.0259971860493045, "Should be '\\1'#2");
|
||||
// Recache original seedrandom.
|
||||
proxyquire('../seedrandom', {});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
415
build/node_modules/seedrandom/test/lib/qunit.css
generated
vendored
Normal file
415
build/node_modules/seedrandom/test/lib/qunit.css
generated
vendored
Normal file
@@ -0,0 +1,415 @@
|
||||
/*!
|
||||
* QUnit 2.1.0
|
||||
* https://qunitjs.com/
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
* Released under the MIT license
|
||||
* https://jquery.org/license
|
||||
*
|
||||
* Date: 2016-12-06T04:45Z
|
||||
*/
|
||||
|
||||
/** Font Family and Sizes */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
|
||||
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-tests { font-size: smaller; }
|
||||
|
||||
|
||||
/** Resets */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/** Header (excluding toolbar) */
|
||||
|
||||
#qunit-header {
|
||||
padding: 0.5em 0 0.5em 1em;
|
||||
|
||||
color: #8699A4;
|
||||
background-color: #0D3349;
|
||||
|
||||
font-size: 1.5em;
|
||||
line-height: 1em;
|
||||
font-weight: 400;
|
||||
|
||||
border-radius: 5px 5px 0 0;
|
||||
}
|
||||
|
||||
#qunit-header a {
|
||||
text-decoration: none;
|
||||
color: #C2CCD1;
|
||||
}
|
||||
|
||||
#qunit-header a:hover,
|
||||
#qunit-header a:focus {
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
#qunit-banner {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
#qunit-filteredTest {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
color: #366097;
|
||||
background-color: #F4FF77;
|
||||
}
|
||||
|
||||
#qunit-userAgent {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
color: #FFF;
|
||||
background-color: #2B81AF;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
|
||||
}
|
||||
|
||||
|
||||
/** Toolbar */
|
||||
|
||||
#qunit-testrunner-toolbar {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
color: #5E740B;
|
||||
background-color: #EEE;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar .clearfix {
|
||||
height: 0;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar input[type=checkbox],
|
||||
#qunit-testrunner-toolbar input[type=radio] {
|
||||
margin: 3px;
|
||||
vertical-align: -2px;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar input[type=text] {
|
||||
box-sizing: border-box;
|
||||
height: 1.6em;
|
||||
}
|
||||
|
||||
.qunit-url-config,
|
||||
.qunit-filter,
|
||||
#qunit-modulefilter {
|
||||
display: inline-block;
|
||||
line-height: 2.1em;
|
||||
}
|
||||
|
||||
.qunit-filter,
|
||||
#qunit-modulefilter {
|
||||
float: right;
|
||||
position: relative;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
.qunit-url-config label {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-search {
|
||||
box-sizing: border-box;
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-search-container:after {
|
||||
position: absolute;
|
||||
right: 0.3em;
|
||||
content: "\25bc";
|
||||
color: black;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown {
|
||||
/* align with #qunit-modulefilter-search */
|
||||
box-sizing: border-box;
|
||||
width: 400px;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
margin-top: 0.8em;
|
||||
|
||||
border: 1px solid #D3D3D3;
|
||||
border-top: none;
|
||||
border-radius: 0 0 .25em .25em;
|
||||
color: #000;
|
||||
background-color: #F5F5F5;
|
||||
z-index: 99;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown .clickable.checked {
|
||||
font-weight: bold;
|
||||
color: #000;
|
||||
background-color: #D2E0E6;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown .clickable:hover {
|
||||
color: #FFF;
|
||||
background-color: #0D3349;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-actions {
|
||||
display: block;
|
||||
overflow: auto;
|
||||
|
||||
/* align with #qunit-modulefilter-dropdown-list */
|
||||
font: smaller/1.5em sans-serif;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > * {
|
||||
box-sizing: border-box;
|
||||
max-height: 2.8em;
|
||||
display: block;
|
||||
padding: 0.4em;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > button {
|
||||
float: right;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > :last-child {
|
||||
/* insert padding to align with checkbox margins */
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
border-top: 2px groove threedhighlight;
|
||||
padding: 0.4em 0 0;
|
||||
font: smaller/1.5em sans-serif;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown-list li {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-dropdown-list .clickable {
|
||||
display: block;
|
||||
padding-left: 0.15em;
|
||||
}
|
||||
|
||||
|
||||
/** Tests: Pass/Fail */
|
||||
|
||||
#qunit-tests {
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests li {
|
||||
padding: 0.4em 1em 0.4em 1em;
|
||||
border-bottom: 1px solid #FFF;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests > li {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests li.running,
|
||||
#qunit-tests li.pass,
|
||||
#qunit-tests li.fail,
|
||||
#qunit-tests li.skipped {
|
||||
display: list-item;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass li.running,
|
||||
#qunit-tests.hidepass li.pass {
|
||||
visibility: hidden;
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#qunit-tests li.skipped strong {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#qunit-tests li a {
|
||||
padding: 0.5em;
|
||||
color: #C2CCD1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests li p a {
|
||||
padding: 0.25em;
|
||||
color: #6B6464;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#qunit-tests li .runtime {
|
||||
float: right;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
.qunit-assert-list {
|
||||
margin-top: 0.5em;
|
||||
padding: 0.5em;
|
||||
|
||||
background-color: #FFF;
|
||||
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.qunit-source {
|
||||
margin: 0.6em 0 0.3em;
|
||||
}
|
||||
|
||||
.qunit-collapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests table {
|
||||
border-collapse: collapse;
|
||||
margin-top: 0.2em;
|
||||
}
|
||||
|
||||
#qunit-tests th {
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
padding: 0 0.5em 0 0;
|
||||
}
|
||||
|
||||
#qunit-tests td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#qunit-tests pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#qunit-tests del {
|
||||
color: #374E0C;
|
||||
background-color: #E0F2BE;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests ins {
|
||||
color: #500;
|
||||
background-color: #FFCACA;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/*** Test Counts */
|
||||
|
||||
#qunit-tests b.counts { color: #000; }
|
||||
#qunit-tests b.passed { color: #5E740B; }
|
||||
#qunit-tests b.failed { color: #710909; }
|
||||
|
||||
#qunit-tests li li {
|
||||
padding: 5px;
|
||||
background-color: #FFF;
|
||||
border-bottom: none;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
/*** Passing Styles */
|
||||
|
||||
#qunit-tests li li.pass {
|
||||
color: #3C510C;
|
||||
background-color: #FFF;
|
||||
border-left: 10px solid #C6E746;
|
||||
}
|
||||
|
||||
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
|
||||
#qunit-tests .pass .test-name { color: #366097; }
|
||||
|
||||
#qunit-tests .pass .test-actual,
|
||||
#qunit-tests .pass .test-expected { color: #999; }
|
||||
|
||||
#qunit-banner.qunit-pass { background-color: #C6E746; }
|
||||
|
||||
/*** Failing Styles */
|
||||
|
||||
#qunit-tests li li.fail {
|
||||
color: #710909;
|
||||
background-color: #FFF;
|
||||
border-left: 10px solid #EE5757;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
#qunit-tests > li:last-child {
|
||||
border-radius: 0 0 5px 5px;
|
||||
}
|
||||
|
||||
#qunit-tests .fail { color: #000; background-color: #EE5757; }
|
||||
#qunit-tests .fail .test-name,
|
||||
#qunit-tests .fail .module-name { color: #000; }
|
||||
|
||||
#qunit-tests .fail .test-actual { color: #EE5757; }
|
||||
#qunit-tests .fail .test-expected { color: #008000; }
|
||||
|
||||
#qunit-banner.qunit-fail { background-color: #EE5757; }
|
||||
|
||||
/*** Skipped tests */
|
||||
|
||||
#qunit-tests .skipped {
|
||||
background-color: #EBECE9;
|
||||
}
|
||||
|
||||
#qunit-tests .qunit-skipped-label {
|
||||
background-color: #F4FF77;
|
||||
display: inline-block;
|
||||
font-style: normal;
|
||||
color: #366097;
|
||||
line-height: 1.8em;
|
||||
padding: 0 0.5em;
|
||||
margin: -0.4em 0.4em -0.4em 0;
|
||||
}
|
||||
|
||||
/** Result */
|
||||
|
||||
#qunit-testresult {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
|
||||
color: #2B81AF;
|
||||
background-color: #D2E0E6;
|
||||
|
||||
border-bottom: 1px solid #FFF;
|
||||
}
|
||||
#qunit-testresult .module-name {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/** Fixture */
|
||||
|
||||
#qunit-fixture {
|
||||
position: absolute;
|
||||
top: -10000px;
|
||||
left: -10000px;
|
||||
width: 1000px;
|
||||
height: 1000px;
|
||||
}
|
||||
4349
build/node_modules/seedrandom/test/lib/qunit.js
generated
vendored
Normal file
4349
build/node_modules/seedrandom/test/lib/qunit.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2142
build/node_modules/seedrandom/test/lib/require.js
generated
vendored
Normal file
2142
build/node_modules/seedrandom/test/lib/require.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
44
build/node_modules/seedrandom/test/newapi.html
generated
vendored
Normal file
44
build/node_modules/seedrandom/test/newapi.html
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script src="../seedrandom.min.js"></script>
|
||||
<script>
|
||||
QUnit.module("New API Test");
|
||||
|
||||
QUnit.test("Check that we can use new", function(assert) {
|
||||
|
||||
assert.ok(true, "Seeded random created with new:");
|
||||
var check = [];
|
||||
var prng = new Math.seedrandom(1);
|
||||
var r;
|
||||
for (var j = 0; j < 5; ++j) {
|
||||
r = prng();
|
||||
assert.ok(true, r);
|
||||
check.push(r);
|
||||
}
|
||||
assert.ok(true, "Native random:");
|
||||
for (var j = 0; j < 5; ++j) {
|
||||
r = Math.random();
|
||||
assert.ok(true, r);
|
||||
check.push(r);
|
||||
}
|
||||
var seed = Math.seedrandom(1);
|
||||
assert.ok(true, "Overridden random without new " +
|
||||
"(return value " + seed + "):");
|
||||
for (var j = 0; j < 10; ++j) {
|
||||
r = Math.random();
|
||||
if (j < 5) {
|
||||
assert.equal(check[j], r, r + " vs " + check[j]);
|
||||
} else {
|
||||
assert.ok(check[j] != r, "unequal: " + r + " vs " + check[j]);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
226
build/node_modules/seedrandom/test/nodetest.js
generated
vendored
Normal file
226
build/node_modules/seedrandom/test/nodetest.js
generated
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
var assert = require("assert");
|
||||
var seedrandom = require("../seedrandom");
|
||||
var requirejs = require("requirejs");
|
||||
|
||||
// Stub out requirejs if in the browser via browserify.
|
||||
if (!requirejs.config) {
|
||||
requirejs = require;
|
||||
} else {
|
||||
requirejs.config({
|
||||
baseUrl: __dirname
|
||||
});
|
||||
}
|
||||
|
||||
describe("Nodejs API Test", function() {
|
||||
|
||||
it('should pass basic tests.', function() {
|
||||
var original = Math.random,
|
||||
result, r, xprng, obj, as2, as3, autoseed1, myrng,
|
||||
firstprng, secondprng, thirdprng, rng;
|
||||
|
||||
result = Math.seedrandom('hello.');
|
||||
firstprng = Math.random;
|
||||
assert.ok(original !== firstprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
|
||||
// should be able to autoseed
|
||||
result = Math.seedrandom();
|
||||
secondprng = Math.random;
|
||||
assert.ok(original !== secondprng, "Should change Math.random.");
|
||||
assert.ok(firstprng !== secondprng, "Should change Math.random.");
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.ok(r > 0, "Should be posititive.");
|
||||
assert.ok(r < 1, "Should be less than 1.");
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.3752569768646784, "Should not be 'hello.'#2");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
autoseed1 = r;
|
||||
|
||||
// should be able to add entropy.
|
||||
result = Math.seedrandom('added entropy.', { entropy:true });
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
thirdprng = Math.random;
|
||||
assert.ok(thirdprng !== secondprng, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Reset to original Math.random.
|
||||
Math.random = original;
|
||||
// should be able to use new Math.seedrandom('hello.')
|
||||
myrng = new Math.seedrandom('hello.');
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// should be able to use seedrandom('hello.')"
|
||||
rng = seedrandom('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
|
||||
// Global PRNG: set Math.random.
|
||||
// should be able to use seedrandom('hello.', { global: true })
|
||||
result = seedrandom('hello.', { global: true });
|
||||
assert.equal(result, 'hello.', "Should return short seed.");
|
||||
assert.ok(original != Math.random, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// Autoseeded non-global
|
||||
Math.random = original;
|
||||
// should be able to use seedrandom()
|
||||
result = seedrandom();
|
||||
assert.equal(typeof(result), 'function', "Should return function.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
|
||||
// Mixing accumulated entropy.
|
||||
// should be able to use seedrandom('added entropy.', { entropy: true })
|
||||
rng = seedrandom('added entropy.', { entropy: true });
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Legacy calling convention for mixing accumulated entropy.
|
||||
// should be able to use seedrandom('added entropy.', true)
|
||||
rng = seedrandom('added entropy.', true);
|
||||
r = result();
|
||||
// got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// The pass option
|
||||
// should be able to use Math.seedrandom(null, { pass: ...
|
||||
obj = Math.seedrandom(null, { pass: function(prng, seed) {
|
||||
return { random: prng, seed: seed };
|
||||
}});
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== obj.random, "Should be different from Math.random.");
|
||||
assert.equal(typeof(obj.random), 'function', "Should return a PRNG function.");
|
||||
assert.equal(typeof(obj.seed), 'string', "Should return a seed.");
|
||||
as2 = obj.random();
|
||||
assert.ok(as2 != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
rng = seedrandom(obj.seed);
|
||||
as3 = rng();
|
||||
assert.equal(as2, as3, "Should be reproducible when using the seed.");
|
||||
|
||||
// Exercise pass again, with explicit seed and global
|
||||
// should be able to use Math.seedrandom('hello.', { pass: ...
|
||||
result = Math.seedrandom('hello.', {
|
||||
global: 'abc',
|
||||
pass: function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert");
|
||||
assert.equal(global, 'abc', "Callback arg #3 passed through.");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'def';
|
||||
}});
|
||||
assert.equal(result, 'def', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Legacy third argument callback argument:
|
||||
// should be able to use Math.seedrandom('hello.', { global: 50 }, callback)
|
||||
result = Math.seedrandom('hello.', { global: 50 },
|
||||
function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert");
|
||||
assert.equal(global, 50, "Callback arg #3 assert");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'zzz';
|
||||
});
|
||||
assert.equal(result, 'zzz', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Global: false.
|
||||
// should be able to use new Math.seedrandom('hello.', {global: false})
|
||||
myrng = new Math.seedrandom('hello.', {global:false});
|
||||
assert.equal(typeof(myrng), 'function', "Should return a PRNG funciton.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// options = {} when a method of Math.
|
||||
// should be able to use Math.seedrandom('hello.', {})
|
||||
result = Math.seedrandom('hello.');
|
||||
xprng = Math.random;
|
||||
assert.ok(original !== xprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
Math.random = original;
|
||||
|
||||
// options = {} when not a method of Math
|
||||
// should be able to use seedrandom('hello.', {})
|
||||
rng = seedrandom('hello.', {});
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
});
|
||||
|
||||
it('should support state api.', function() {
|
||||
// Verify that there is no state method
|
||||
var dummy = seedrandom('hello');
|
||||
var unexpected = -1;
|
||||
var expected = -1;
|
||||
try {
|
||||
unexpected = dummy.state();
|
||||
} catch(e) {
|
||||
expected = 1;
|
||||
}
|
||||
assert.equal(unexpected, -1);
|
||||
assert.equal(expected, 1);
|
||||
var count = 0;
|
||||
for (var x in dummy) {
|
||||
if (x == 'state') count += 1;
|
||||
}
|
||||
assert.equal(count, 0);
|
||||
|
||||
// Verify that a state method can be added
|
||||
var saveable = seedrandom("secret-seed", {state: true});
|
||||
var ordinary = seedrandom("secret-seed");
|
||||
for (var j = 0; j < 1e2; ++j) {
|
||||
assert.equal(ordinary(), saveable());
|
||||
}
|
||||
var virgin = seedrandom("secret-seed");
|
||||
var saved = saveable.state();
|
||||
var replica = seedrandom("", {state: saved});
|
||||
for (var j = 0; j < 1e2; ++j) {
|
||||
var r = replica();
|
||||
assert.equal(r, saveable());
|
||||
assert.equal(r, ordinary());
|
||||
assert.ok(r != virgin());
|
||||
}
|
||||
});
|
||||
|
||||
it('should support requirejs in node.', function() {
|
||||
var original = Math.random;
|
||||
var rsr = requirejs('../seedrandom');
|
||||
var rng = rsr('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
var r = rng();
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
});
|
||||
|
||||
// End of test.
|
||||
|
||||
});
|
||||
195
build/node_modules/seedrandom/test/options.html
generated
vendored
Normal file
195
build/node_modules/seedrandom/test/options.html
generated
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="../seedrandom.min.js"></script>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script>
|
||||
QUnit.module("Options API Test");
|
||||
|
||||
QUnit.test("Verify that we can use documented options", function(assert) {
|
||||
assert.ok(true, "Seeded random created with new:");
|
||||
|
||||
var original = Math.random;
|
||||
|
||||
assert.ok(true, "Using Math.seedrandom('hello.')");
|
||||
var result = Math.seedrandom('hello.');
|
||||
var firstprng = Math.random;
|
||||
assert.ok(original !== firstprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
var r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
|
||||
assert.ok(true, "Using Math.seedrandom()");
|
||||
result = Math.seedrandom();
|
||||
var secondprng = Math.random;
|
||||
assert.ok(original !== secondprng, "Should change Math.random.");
|
||||
assert.ok(firstprng !== secondprng, "Should change Math.random.");
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
var autoseed1 = r;
|
||||
|
||||
assert.ok(true, "Using Math.seedrandom('added entropy.', { entropy:true })");
|
||||
result = Math.seedrandom('added entropy.', { entropy:true });
|
||||
assert.equal(result.length, 256, "Should return short seed.");
|
||||
var thirdprng = Math.random;
|
||||
assert.ok(thirdprng !== secondprng, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Reset to original Math.random.
|
||||
Math.random = original;
|
||||
assert.ok(true, "Using new Math.seedrandom('hello.')");
|
||||
var myrng = new Math.seedrandom('hello.');
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// Use "quick" to get only 32 bits of randomness in a float.
|
||||
assert.equal(myrng.quick(), 0.3752569768112153, "Should be quick #1.1");
|
||||
|
||||
// Use "int32" to get a 32 bit (signed) integer
|
||||
assert.equal(myrng.int32(), 986220731, "Should be int32 #1.2");
|
||||
|
||||
// As if brought in by node.js
|
||||
var seedrandom = Math.seedrandom;
|
||||
|
||||
assert.ok(true, "Using seedrandom('hello.')");
|
||||
var rng = seedrandom('hello.');
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
|
||||
// Global PRNG: set Math.random.
|
||||
assert.ok(true, "Using seedrandom('hello.', { global: true })");
|
||||
result = seedrandom('hello.', { global: true });
|
||||
assert.equal(result, 'hello.', "Should return short seed.");
|
||||
assert.ok(original != Math.random, "Should change Math.random.");
|
||||
r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// Autoseeded non-global
|
||||
Math.random = original;
|
||||
assert.ok(true, "Using seedrandom()");
|
||||
result = seedrandom();
|
||||
assert.equal(typeof(result), 'function', "Should return function.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
r = result();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
assert.ok(r != 0.7316977468919549, "Should not be 'hello.'#3");
|
||||
|
||||
// Mixing accumulated entropy.
|
||||
assert.ok(true, "Using seedrandom('added entropy.', { entropy: true })");
|
||||
rng = seedrandom('added entropy.', { entropy: true });
|
||||
r = result();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// Legacy calling convention for mixing accumulated entropy.
|
||||
assert.ok(true, "Using seedrandom('added entropy.', true)");
|
||||
rng = seedrandom('added entropy.', true);
|
||||
r = result();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.ok(r != autoseed1, "Should not repeat previous autoseed.");
|
||||
assert.ok(r != 0.597067214994467, "Should not be 'added entropy.'#1");
|
||||
|
||||
// The pass option
|
||||
assert.ok(true, "Using Math.seedrandom(null, { pass: ...");
|
||||
var obj = Math.seedrandom(null, { pass: function(prng, seed) {
|
||||
return { random: prng, seed: seed };
|
||||
}});
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== obj.random, "Should be different from Math.random.");
|
||||
assert.equal(typeof(obj.random), 'function', "Should return a PRNG function.");
|
||||
assert.equal(typeof(obj.seed), 'string', "Should return a seed.");
|
||||
var as2 = obj.random();
|
||||
assert.ok(as2 != 0.9282578795792454, "Should not be 'hello.'#1");
|
||||
rng = seedrandom(obj.seed);
|
||||
var as3 = rng();
|
||||
assert.equal(as2, as3, "Should be reproducible when using the seed.");
|
||||
|
||||
// Exercise pass again, with explicit seed and global
|
||||
assert.ok(true, "Using Math.seedrandom('hello.', { pass: ...");
|
||||
result = Math.seedrandom('hello.', {
|
||||
global: 'abc',
|
||||
pass: function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert.ok");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert.ok");
|
||||
assert.equal(global, 'abc', "Callback arg #3 passed through.");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'def';
|
||||
}});
|
||||
assert.equal(result, 'def', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Legacy third argument callback argument:
|
||||
assert.ok(true, "Using Math.seedrandom('hello.', { global: 50 }, callback)");
|
||||
result = Math.seedrandom('hello.', { global: 50 },
|
||||
function(prng, seed, global) {
|
||||
assert.equal(typeof(prng), 'function', "Callback arg #1 assert.ok");
|
||||
assert.equal(seed, 'hello.', "Callback arg #2 assert.ok");
|
||||
assert.equal(global, 50, "Callback arg #3 assert.ok");
|
||||
assert.equal(prng(), 0.9282578795792454, "Should be 'hello.'#1");
|
||||
return 'zzz';
|
||||
});
|
||||
assert.equal(result, 'zzz', "Should return value from callback.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
|
||||
// Global: false.
|
||||
assert.ok(true, "Using new Math.seedrandom('hello.', {global: false})");
|
||||
myrng = new Math.seedrandom('hello.', {global:false});
|
||||
assert.equal(typeof(myrng), 'function', "Should return a PRNG funciton.");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== myrng, "PRNG should not be Math.random.");
|
||||
r = myrng();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
|
||||
// options = {} when a method of Math.
|
||||
assert.ok(true, "Using Math.seedrandom('hello.', {})");
|
||||
var result = Math.seedrandom('hello.');
|
||||
var xprng = Math.random;
|
||||
assert.ok(original !== xprng, "Should change Math.random.");
|
||||
assert.equal(result, "hello.", "Should return short seed.");
|
||||
var r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
r = Math.random();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.3752569768646784, "Should be 'hello.'#2");
|
||||
Math.random = original;
|
||||
|
||||
// options = {} when not a method of Math
|
||||
assert.ok(true, "Using seedrandom('hello.', {})");
|
||||
rng = seedrandom('hello.', {});
|
||||
assert.equal(typeof(rng), 'function', "Should return a function.");
|
||||
r = rng();
|
||||
assert.ok(true, "Got " + r);
|
||||
assert.equal(r, 0.9282578795792454, "Should be 'hello.'#1");
|
||||
assert.ok(original === Math.random, "Should not change Math.random.");
|
||||
assert.ok(original !== rng, "PRNG should not be Math.random.");
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
125
build/node_modules/seedrandom/test/out/dieharder-report.txt
generated
vendored
Normal file
125
build/node_modules/seedrandom/test/out/dieharder-report.txt
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
#=============================================================================#
|
||||
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
|
||||
#=============================================================================#
|
||||
rng_name |rands/second| Seed |
|
||||
stdin_input_raw| 8.07e+05 | 254212981|
|
||||
#=============================================================================#
|
||||
test_name |ntup| tsamples |psamples| p-value |Assessment
|
||||
#=============================================================================#
|
||||
diehard_birthdays| 0| 100| 100|0.55960061| PASSED
|
||||
diehard_operm5| 0| 1000000| 100|0.10062010| PASSED
|
||||
diehard_rank_32x32| 0| 40000| 100|0.70957907| PASSED
|
||||
diehard_rank_6x8| 0| 100000| 100|0.55953143| PASSED
|
||||
diehard_bitstream| 0| 2097152| 100|0.22843857| PASSED
|
||||
diehard_opso| 0| 2097152| 100|0.72251086| PASSED
|
||||
diehard_oqso| 0| 2097152| 100|0.30642074| PASSED
|
||||
diehard_dna| 0| 2097152| 100|0.30448899| PASSED
|
||||
diehard_count_1s_str| 0| 256000| 100|0.23557064| PASSED
|
||||
diehard_count_1s_byt| 0| 256000| 100|0.71300874| PASSED
|
||||
diehard_parking_lot| 0| 12000| 100|0.88217430| PASSED
|
||||
diehard_2dsphere| 2| 8000| 100|0.32366362| PASSED
|
||||
diehard_3dsphere| 3| 4000| 100|0.30804215| PASSED
|
||||
diehard_squeeze| 0| 100000| 100|0.97856588| PASSED
|
||||
diehard_sums| 0| 100| 100|0.01512286| PASSED
|
||||
diehard_runs| 0| 100000| 100|0.39065054| PASSED
|
||||
diehard_runs| 0| 100000| 100|0.10369088| PASSED
|
||||
diehard_craps| 0| 200000| 100|0.57875078| PASSED
|
||||
diehard_craps| 0| 200000| 100|0.96945165| PASSED
|
||||
marsaglia_tsang_gcd| 0| 10000000| 100|0.58793715| PASSED
|
||||
marsaglia_tsang_gcd| 0| 10000000| 100|0.59724594| PASSED
|
||||
sts_monobit| 1| 100000| 100|0.49155110| PASSED
|
||||
sts_runs| 2| 100000| 100|0.01880740| PASSED
|
||||
sts_serial| 1| 100000| 100|0.79060354| PASSED
|
||||
sts_serial| 2| 100000| 100|0.91055644| PASSED
|
||||
sts_serial| 3| 100000| 100|0.15984346| PASSED
|
||||
sts_serial| 3| 100000| 100|0.04426690| PASSED
|
||||
sts_serial| 4| 100000| 100|0.31589675| PASSED
|
||||
sts_serial| 4| 100000| 100|0.65789943| PASSED
|
||||
sts_serial| 5| 100000| 100|0.84228003| PASSED
|
||||
sts_serial| 5| 100000| 100|0.28748169| PASSED
|
||||
sts_serial| 6| 100000| 100|0.00092985| WEAK
|
||||
sts_serial| 6| 100000| 100|0.06074248| PASSED
|
||||
sts_serial| 7| 100000| 100|0.54740122| PASSED
|
||||
sts_serial| 7| 100000| 100|0.30286638| PASSED
|
||||
sts_serial| 8| 100000| 100|0.56593073| PASSED
|
||||
sts_serial| 8| 100000| 100|0.48256390| PASSED
|
||||
sts_serial| 9| 100000| 100|0.70850963| PASSED
|
||||
sts_serial| 9| 100000| 100|0.63732762| PASSED
|
||||
sts_serial| 10| 100000| 100|0.70209276| PASSED
|
||||
sts_serial| 10| 100000| 100|0.99576606| WEAK
|
||||
sts_serial| 11| 100000| 100|0.96272563| PASSED
|
||||
sts_serial| 11| 100000| 100|0.76682898| PASSED
|
||||
sts_serial| 12| 100000| 100|0.51522677| PASSED
|
||||
sts_serial| 12| 100000| 100|0.49381681| PASSED
|
||||
sts_serial| 13| 100000| 100|0.24260261| PASSED
|
||||
sts_serial| 13| 100000| 100|0.41953338| PASSED
|
||||
sts_serial| 14| 100000| 100|0.34770045| PASSED
|
||||
sts_serial| 14| 100000| 100|0.16117277| PASSED
|
||||
sts_serial| 15| 100000| 100|0.27319992| PASSED
|
||||
sts_serial| 15| 100000| 100|0.61170864| PASSED
|
||||
sts_serial| 16| 100000| 100|0.90638742| PASSED
|
||||
sts_serial| 16| 100000| 100|0.60186602| PASSED
|
||||
rgb_bitdist| 1| 100000| 100|0.72630216| PASSED
|
||||
rgb_bitdist| 2| 100000| 100|0.61396597| PASSED
|
||||
rgb_bitdist| 3| 100000| 100|0.40711729| PASSED
|
||||
rgb_bitdist| 4| 100000| 100|0.94730365| PASSED
|
||||
rgb_bitdist| 5| 100000| 100|0.95781972| PASSED
|
||||
rgb_bitdist| 6| 100000| 100|0.15054771| PASSED
|
||||
rgb_bitdist| 7| 100000| 100|0.25022202| PASSED
|
||||
rgb_bitdist| 8| 100000| 100|0.66027754| PASSED
|
||||
rgb_bitdist| 9| 100000| 100|0.86566842| PASSED
|
||||
rgb_bitdist| 10| 100000| 100|0.55219204| PASSED
|
||||
rgb_bitdist| 11| 100000| 100|0.73446935| PASSED
|
||||
rgb_bitdist| 12| 100000| 100|0.99761332| WEAK
|
||||
rgb_minimum_distance| 2| 10000| 1000|0.42222311| PASSED
|
||||
rgb_minimum_distance| 3| 10000| 1000|0.81566417| PASSED
|
||||
rgb_minimum_distance| 4| 10000| 1000|0.84024874| PASSED
|
||||
rgb_minimum_distance| 5| 10000| 1000|0.37732026| PASSED
|
||||
rgb_permutations| 2| 100000| 100|0.10996142| PASSED
|
||||
rgb_permutations| 3| 100000| 100|0.64682554| PASSED
|
||||
rgb_permutations| 4| 100000| 100|0.75843859| PASSED
|
||||
rgb_permutations| 5| 100000| 100|0.95248930| PASSED
|
||||
rgb_lagged_sum| 0| 1000000| 100|0.57812648| PASSED
|
||||
rgb_lagged_sum| 1| 1000000| 100|0.67863162| PASSED
|
||||
rgb_lagged_sum| 2| 1000000| 100|0.70003210| PASSED
|
||||
rgb_lagged_sum| 3| 1000000| 100|0.50312943| PASSED
|
||||
rgb_lagged_sum| 4| 1000000| 100|0.80009739| PASSED
|
||||
rgb_lagged_sum| 5| 1000000| 100|0.66383600| PASSED
|
||||
rgb_lagged_sum| 6| 1000000| 100|0.65640392| PASSED
|
||||
rgb_lagged_sum| 7| 1000000| 100|0.10710511| PASSED
|
||||
rgb_lagged_sum| 8| 1000000| 100|0.70414014| PASSED
|
||||
rgb_lagged_sum| 9| 1000000| 100|0.63857571| PASSED
|
||||
rgb_lagged_sum| 10| 1000000| 100|0.25221229| PASSED
|
||||
rgb_lagged_sum| 11| 1000000| 100|0.04199433| PASSED
|
||||
rgb_lagged_sum| 12| 1000000| 100|0.82738115| PASSED
|
||||
rgb_lagged_sum| 13| 1000000| 100|0.28316509| PASSED
|
||||
rgb_lagged_sum| 14| 1000000| 100|0.21184422| PASSED
|
||||
rgb_lagged_sum| 15| 1000000| 100|0.35537687| PASSED
|
||||
rgb_lagged_sum| 16| 1000000| 100|0.40157319| PASSED
|
||||
rgb_lagged_sum| 17| 1000000| 100|0.98108259| PASSED
|
||||
rgb_lagged_sum| 18| 1000000| 100|0.65892868| PASSED
|
||||
rgb_lagged_sum| 19| 1000000| 100|0.61659671| PASSED
|
||||
rgb_lagged_sum| 20| 1000000| 100|0.21462018| PASSED
|
||||
rgb_lagged_sum| 21| 1000000| 100|0.94489214| PASSED
|
||||
rgb_lagged_sum| 22| 1000000| 100|0.76019491| PASSED
|
||||
rgb_lagged_sum| 23| 1000000| 100|0.21024028| PASSED
|
||||
rgb_lagged_sum| 24| 1000000| 100|0.25249456| PASSED
|
||||
rgb_lagged_sum| 25| 1000000| 100|0.87385459| PASSED
|
||||
rgb_lagged_sum| 26| 1000000| 100|0.81553540| PASSED
|
||||
rgb_lagged_sum| 27| 1000000| 100|0.94450657| PASSED
|
||||
rgb_lagged_sum| 28| 1000000| 100|0.82470366| PASSED
|
||||
rgb_lagged_sum| 29| 1000000| 100|0.93993722| PASSED
|
||||
rgb_lagged_sum| 30| 1000000| 100|0.52675692| PASSED
|
||||
rgb_lagged_sum| 31| 1000000| 100|0.59975558| PASSED
|
||||
rgb_lagged_sum| 32| 1000000| 100|0.27951088| PASSED
|
||||
rgb_kstest_test| 0| 10000| 1000|0.49707175| PASSED
|
||||
dab_bytedistrib| 0| 51200000| 1|0.73019918| PASSED
|
||||
dab_dct| 256| 50000| 1|0.33856081| PASSED
|
||||
Preparing to run test 207. ntuple = 0
|
||||
dab_filltree| 32| 15000000| 1|0.92953640| PASSED
|
||||
dab_filltree| 32| 15000000| 1|0.10970674| PASSED
|
||||
Preparing to run test 208. ntuple = 0
|
||||
dab_filltree2| 0| 5000000| 1|0.88411850| PASSED
|
||||
dab_filltree2| 1| 5000000| 1|0.56835378| PASSED
|
||||
Preparing to run test 209. ntuple = 0
|
||||
dab_monobit2| 12| 65000000| 1|0.07987839| PASSED
|
||||
122
build/node_modules/seedrandom/test/prngtest.js
generated
vendored
Normal file
122
build/node_modules/seedrandom/test/prngtest.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
// A simple smoke test and benchmark for the generators.
|
||||
|
||||
var assert = require('assert');
|
||||
var xor128 = require('../lib/xor128');
|
||||
var xorwow = require('../lib/xorwow');
|
||||
var xs7 = require('../lib/xorshift7');
|
||||
var xor4096 = require('../lib/xor4096');
|
||||
var tychei = require('../lib/tychei');
|
||||
var alea = require('../lib/alea');
|
||||
var sr = require('../seedrandom');
|
||||
|
||||
describe("XOR-Shift generator test", function() {
|
||||
|
||||
var benchmarks = { native: { rand: Math.random, times: [] } };
|
||||
|
||||
function test(label, alg, double1, float3, int4, hc, qc, ec, e2c) {
|
||||
var fn = alg(1);
|
||||
var fn2 = alg('hello.', { state: true });
|
||||
benchmarks[label] = {rand: fn.quick, times: []};
|
||||
it("should use " + label + " correctly", function() {
|
||||
if (double1 != null) assert.equal(fn.double(), double1);
|
||||
if (float3 != null) assert.equal(fn.quick(), float3);
|
||||
if (int4 != null) assert.equal(fn.int32(), int4);
|
||||
assert(fn() > 0);
|
||||
assert(fn() < 1);
|
||||
assert(fn2() > 0);
|
||||
// Internal state is visible only if requested.
|
||||
assert(!('state' in fn));
|
||||
assert('state' in fn2);
|
||||
var ss = fn2.state();
|
||||
var rs = fn2();
|
||||
assert(rs < 1);
|
||||
var j, h = 0, q = 0, e = 0, r, p, e2 = 0;
|
||||
for (j = 0; j < 1024; ++j) {
|
||||
r = fn();
|
||||
if (r < 0.5) h += 1;
|
||||
if (r < 0.25) q += 1;
|
||||
if (r < 0.125) e += 1;
|
||||
r2 = fn2();
|
||||
if (r2 < 0.125) e2 += 1;
|
||||
}
|
||||
if (hc != null) {
|
||||
assert.equal(h, hc);
|
||||
assert.equal(q, qc);
|
||||
assert.equal(e, ec);
|
||||
assert.equal(e2, e2c);
|
||||
h = q = e = p = 0;
|
||||
for (j = 0; j < 1024; ++j) {
|
||||
r = fn.double();
|
||||
if (r < 0.5) h += 1;
|
||||
if (r < 0.25) q += 1;
|
||||
if (r < 0.125) e += 1;
|
||||
if (fn.int32() >= 0) p += 1;
|
||||
}
|
||||
// Sanity-check double() and int32.
|
||||
assert(h >= 480 && h <= 543, h);
|
||||
assert(q >= 226 && q <= 286, q);
|
||||
assert(e >= 100 && e <= 156, e);
|
||||
assert(e2 >= 100 && e2 <= 156, e2);
|
||||
assert(p >= 482 && p <= 543, p);
|
||||
}
|
||||
var fn3 = alg(0, { state: ss });
|
||||
assert.equal(fn3(), rs);
|
||||
});
|
||||
}
|
||||
|
||||
test("xor128", xor128,
|
||||
0.7963797148975774, 0.22171171731315553, 317177041, 498, 236, 110, 115);
|
||||
test("xorwow", xorwow,
|
||||
0.8178000247146859, 0.8407576507888734, 533150816, 519, 228, 121, 123);
|
||||
test("xorshift7", xs7,
|
||||
0.21241471533241418, 0.9957620368804783, -1678071207, 510, 261, 143, 124);
|
||||
test("tychei", tychei,
|
||||
0.42331440041340196, 0.9365617581643164, -884984569, 521, 242, 116, 126);
|
||||
test("seedrandom", sr,
|
||||
0.1776348083296759, 0.2160690303426236, 1397712774, 526, 282, 131, 137);
|
||||
test("xor4096", xor4096,
|
||||
0.1520436450538547, 0.4206166828516871, 1312695376, 496, 241, 113, 142);
|
||||
test("alea", alea,
|
||||
0.5260470956849501, 0.47771977609954774, -1625913352, 494, 246, 125, 122);
|
||||
|
||||
it("runs benchmarks", function() {
|
||||
var n = 4;
|
||||
var trials = 10;
|
||||
var top = 4;
|
||||
this.timeout(200 * n * trials);
|
||||
this.slow(30 * n * trials);
|
||||
var fn, k, start, end, j, t;
|
||||
for (k in benchmarks) {
|
||||
fn = benchmarks[k].rand;
|
||||
// warmup.
|
||||
for (j = 0; j < 1e5; ++j) fn();
|
||||
}
|
||||
for (t = 0; t < trials; ++t) {
|
||||
for (k in benchmarks) {
|
||||
fn = benchmarks[k].rand;
|
||||
start = +new Date;
|
||||
// benchmark.
|
||||
for (j = 0; j < n * 1e5; ++j) fn();
|
||||
end = +new Date;
|
||||
benchmarks[k].times.push(end - start);
|
||||
}
|
||||
}
|
||||
for (k in benchmarks) {
|
||||
benchmarks[k].times.sort();
|
||||
}
|
||||
function fastest(array) {
|
||||
var sum = 0;
|
||||
for (var j = 0; j < top; ++j) {
|
||||
sum += array[j];
|
||||
}
|
||||
return sum / top;
|
||||
}
|
||||
var nativetime = fastest(benchmarks.native.times);
|
||||
for (k in benchmarks) {
|
||||
var time = fastest(benchmarks[k].times);
|
||||
console.log(k+ ': ' + time / n + ' nanoseconds per call, ' +
|
||||
(time / nativetime).toFixed(1) + 'x native random.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
3
build/node_modules/seedrandom/test/qunitassert.js
generated
vendored
Normal file
3
build/node_modules/seedrandom/test/qunitassert.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// Use QUnit.assert to mimic node.assert.
|
||||
|
||||
module.exports = QUnit.assert;
|
||||
57
build/node_modules/seedrandom/test/require.html
generated
vendored
Normal file
57
build/node_modules/seedrandom/test/require.html
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/require.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
require.config({
|
||||
paths: {
|
||||
'qunit': 'lib/qunit',
|
||||
'seedrandom': '/seedrandom.min'
|
||||
}
|
||||
});
|
||||
|
||||
require(['qunit', 'seedrandom'], function(QUnit, seedrandom) {
|
||||
QUnit.start();
|
||||
QUnit.module('require.js test');
|
||||
QUnit.test('some normal test', function(assert) {
|
||||
assert.ok(true, "Seeded random created using module:");
|
||||
var check = [];
|
||||
var prng = seedrandom('predictable.');
|
||||
var r;
|
||||
for (var j = 0; j < 5; ++j) {
|
||||
r = prng();
|
||||
assert.ok(true, r + "");
|
||||
check.push(r);
|
||||
}
|
||||
assert.ok(true, "Native random:");
|
||||
for (var j = 0; j < 5; ++j) {
|
||||
r = Math.random();
|
||||
assert.ok(true, r + "");
|
||||
check.push(r);
|
||||
}
|
||||
// Verify against Math.seedrandom.
|
||||
var seed = Math.seedrandom('predictable.');
|
||||
assert.equal(seed, 'predictable.',
|
||||
"Seed should be returned from Math.seedrandom.");
|
||||
for (var j = 0; j < 10; ++j) {
|
||||
r = Math.random();
|
||||
if (j < 5) {
|
||||
assert.equal(check[j], r, "Equal: " + r + " vs " + check[j]);
|
||||
} else {
|
||||
assert.ok(check[j] != r, "Unqual: " + r + " vs " + check[j]);
|
||||
}
|
||||
}
|
||||
document.close();
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
5
build/node_modules/seedrandom/test/run_dieharder.sh
generated
vendored
Executable file
5
build/node_modules/seedrandom/test/run_dieharder.sh
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# http://www.phy.duke.edu/~rgb/General/dieharder.php
|
||||
# How to run dieharder against seedrandom:
|
||||
|
||||
node bitgen.js | dieharder -g 200 -a | tee out/dieharder-report.txt
|
||||
56
build/node_modules/seedrandom/test/state.html
generated
vendored
Normal file
56
build/node_modules/seedrandom/test/state.html
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="lib/qunit.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="../seedrandom.min.js"></script>
|
||||
<script src="lib/qunit.js"></script>
|
||||
<script>
|
||||
QUnit.module("Options API Test");
|
||||
|
||||
QUnit.test("Verify that state method is not normally present",
|
||||
function(assert) {
|
||||
|
||||
var seedrandom = Math.seedrandom;
|
||||
var dummy = seedrandom('hello');
|
||||
var unexpected = -1;
|
||||
var expected = -1;
|
||||
try {
|
||||
unexpected = dummy.state();
|
||||
} catch(e) {
|
||||
expected = 1;
|
||||
}
|
||||
assert.equal(unexpected, -1);
|
||||
assert.equal(expected, 1);
|
||||
var count = 0;
|
||||
for (var x in dummy) {
|
||||
if (x == 'state') count += 1;
|
||||
}
|
||||
assert.equal(count, 0);
|
||||
|
||||
});
|
||||
|
||||
QUnit.test("Verify that state option works as advertised", function(assert) {
|
||||
|
||||
var seedrandom = Math.seedrandom;
|
||||
var saveable = seedrandom("secret-seed", {state: true});
|
||||
var ordinary = seedrandom("secret-seed");
|
||||
for (var j = 0; j < 1e3; ++j) {
|
||||
assert.equal(ordinary(), saveable());
|
||||
}
|
||||
var virgin = seedrandom("secret-seed");
|
||||
var saved = saveable.state();
|
||||
var replica = seedrandom("", {state: saved});
|
||||
for (var j = 0; j < 1e2; ++j) {
|
||||
var r = replica();
|
||||
assert.equal(r, saveable());
|
||||
assert.equal(r, ordinary());
|
||||
assert.ok(r != virgin());
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user