Skip to content

Commit

Permalink
[fix] Mersenne Twister seed_array #712
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Oct 10, 2018
1 parent be8cd96 commit c852cdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion test/random.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,24 @@ describe("random.js", function () {
assert.equal(opts.max, max);
});

it('should return deterministic results when seeded', function() {
it('should return deterministic results when seeded with integer', function() {
faker.seed(100);
var name = faker.name.findName();
assert.equal(name, 'Eva Jenkins');
})

it('should return deterministic results when seeded with array - one element', function() {
faker.seed([10]);
var name = faker.name.findName();
assert.equal(name, 'Duane Kub');
})

it('should return deterministic results when seeded with array - multiple elements', function() {
faker.seed([10, 100, 1000]);
var name = faker.name.findName();
assert.equal(name, 'Alma Shanahan');
})

});

describe("float", function() {
Expand Down
4 changes: 2 additions & 2 deletions vendor/mersenne.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,5 @@ exports.seed_array = function(A) {
{
throw new Error("seed_array(A) must take array of numbers; is " + typeof(A));
}
gen.init_by_array(A);
}
gen.init_by_array(A, A.length);
}

0 comments on commit c852cdf

Please sign in to comment.