Commit c43a1c37 authored by Daniel Goldbach's avatar Daniel Goldbach
Browse files

Use seed random to seed Math.random

parent 0dd467f2
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
"devDependencies": { "devDependencies": {
"smash": "~0.0.12", "smash": "~0.0.12",
"uglify-js": "2.4.0", "uglify-js": "2.4.0",
"vows": "0.7.0" "vows": "0.7.0",
"seedrandom": "0.1.6"
}, },
"scripts": { "scripts": {
"test": "node_modules/.bin/vows" "test": "node_modules/.bin/vows"
......
var vows = require("vows"), var vows = require("vows"),
load = require("../load"), load = require("../load"),
assert = require("../assert"); assert = require("../assert"),
seedrandom = require('seedrandom');
var suite = vows.describe("d3.random"); var suite = vows.describe("d3.random");
...@@ -8,18 +9,24 @@ var suite = vows.describe("d3.random"); ...@@ -8,18 +9,24 @@ var suite = vows.describe("d3.random");
* Testing a random number generator is a bit more complicated than testing * Testing a random number generator is a bit more complicated than testing
* deterministic code, so we use different techniques. * deterministic code, so we use different techniques.
* *
* If the RNG is correct, each test in this suite will pass with probability at * If the RNG is correct, each test in this suite will pass with probability
* least P. The tests have been designed so that P ≥ 98%. If the tests fail * at least P. The tests have been designed so that P ≥ 98%. Specific values
* consistently, d3's RNG is broken. Specific values of P are given above each * of P are given above each case. We use the seedrandom module to get around
* case. * this non-deterministic aspect -- so it is safe to assume that if the tests
* fail, then d3's RNG is broken.
* *
* More on RNG testing here: * More on RNG testing here:
* @see http://www.johndcook.com/Beautiful_Testing_ch10.pdf * @see http://www.johndcook.com/Beautiful_Testing_ch10.pdf
*/ */
// Arbitrarily chosen parameters for the normal RNG // Arbitrarily chosen parameters for the normal RNG.
// It's good practice to set |STDDEV| << |MEAN|.
var STDDEV = 38.8; var STDDEV = 38.8;
var MEAN = 23428; var MEAN = -349234;
// Overwrites Math.random to a seeded random function.
// (by default Math.random is seeded with current time)
Math.seedrandom('a random seed.');
suite.addBatch({ suite.addBatch({
"random": { "random": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment