Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MUR Drupal
d3library
Commits
c43a1c37
Commit
c43a1c37
authored
Nov 24, 2013
by
Daniel Goldbach
Browse files
Use seed random to seed Math.random
parent
0dd467f2
Changes
2
Show whitespace changes
Inline
Sidebyside
package.json
View file @
c43a1c37
...
...
@@ 46,7 +46,8 @@
"devDependencies"
:
{
"
smash
"
:
"
~0.0.12
"
,
"
uglifyjs
"
:
"
2.4.0
"
,
"
vows
"
:
"
0.7.0
"
"
vows
"
:
"
0.7.0
"
,
"
seedrandom
"
:
"
0.1.6
"
},
"scripts"
:
{
"test"
:
"node_modules/.bin/vows"
...
...
test/math/randomtest.js
View file @
c43a1c37
var
vows
=
require
(
"
vows
"
),
load
=
require
(
"
../load
"
),
assert
=
require
(
"
../assert
"
);
assert
=
require
(
"
../assert
"
),
seedrandom
=
require
(
'
seedrandom
'
);
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
* deterministic code, so we use different techniques.
*
* If the RNG is correct, each test in this suite will pass with probability at
* least P. The tests have been designed so that P ≥ 98%. If the tests fail
* consistently, d3's RNG is broken. Specific values of P are given above each
* case.
* If the RNG is correct, each test in this suite will pass with probability
* at least P. The tests have been designed so that P ≥ 98%. Specific values
* of P are given above each case. We use the seedrandom module to get around
* this nondeterministic aspect  so it is safe to assume that if the tests
* fail, then d3's RNG is broken.
*
* More on RNG testing here:
* @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
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
({
"
random
"
:
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment