Permalink
Browse files

Fix SeededRandom's use of Random's alea.

Thanks glasser
  • Loading branch information...
1 parent 8531977 commit d564ab4b99ebd3bca264f463907e038da706eb1f Emily Stark committed Nov 21, 2013
View
2 packages/random/random.js
@@ -95,7 +95,6 @@ var RandomGenerator = function (seedArray) {
var self = this;
if (seedArray !== undefined)
self.alea = Alea.apply(null, seedArray);
- self._Alea = Alea;
};
RandomGenerator.prototype.fraction = function () {
@@ -138,7 +137,6 @@ RandomGenerator.prototype.hexString = function (digits) {
return hexDigits.join('');
}
};
-
RandomGenerator.prototype.id = function () {
var digits = [];
var self = this;
View
1 packages/test-helpers/package.js
@@ -31,4 +31,5 @@ Package.on_test(function (api) {
api.use('tinytest');
api.use(['test-helpers', 'underscore']);
api.add_files('try_all_permutations_test.js', 'client');
+ api.add_files('seeded_random_test.js');
});
View
2 packages/test-helpers/seeded_random.js
@@ -3,7 +3,7 @@ SeededRandom = function(seed) { // seed may be a string or any type
return new SeededRandom(seed);
seed = seed || "seed";
- this.gen = Random.create(seed)._Alea; // from random.js
+ this.gen = Random.create(seed).alea; // from random.js
};
SeededRandom.prototype.next = function() {
return this.gen();
View
15 packages/test-helpers/seeded_random_test.js
@@ -0,0 +1,15 @@
+// XXX SECTION: Meta tests
+
+Tinytest.add("seeded random", function (test) {
+ // Test that two seeded PRNGs with the same seed produce the same values.
+ var seed = "I'm a seed";
+ var sr1 = new SeededRandom(seed);
+ var sr2 = new SeededRandom(seed);
+ var sr1vals = [];
+ var sr2vals = [];
+ for (var i = 0; i < 100; i++) {
+ sr1vals.push(sr1.next());
+ sr2vals.push(sr2.next());
+ }
+ test.equal(sr1vals, sr2vals);
+});

0 comments on commit d564ab4

Please sign in to comment.