aboutsummaryrefslogtreecommitdiff
path: root/lib/random.js
diff options
context:
space:
mode:
authorBrandon Dail <[email protected]>2015-07-15 13:31:51 -0500
committerBrandon Dail <[email protected]>2015-07-15 13:31:51 -0500
commit40c13f210afd9a2cd5bf5f60fba7169c6e35ea44 (patch)
tree5ada284a07669b925acd8da41c0ace2156107d32 /lib/random.js
parenta0465fcd7678812cfe697c3dd045085d94e52cfa (diff)
downloadfaker-40c13f210afd9a2cd5bf5f60fba7169c6e35ea44.tar.xz
faker-40c13f210afd9a2cd5bf5f60fba7169c6e35ea44.zip
Implemented faker.seed method for randomization seeding
Diffstat (limited to 'lib/random.js')
-rw-r--r--lib/random.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/random.js b/lib/random.js
index 2d37c551..fc7e54d9 100644
--- a/lib/random.js
+++ b/lib/random.js
@@ -1,7 +1,15 @@
var mersenne = require('../vendor/mersenne');
-function Random (faker) {
-
+function Random (faker, seed) {
+ // Use a user provided seed if it exists
+ if (seed) {
+ if (Array.isArray(seed) && seed.length) {
+ mersenne.seed_array(seed);
+ }
+ else {
+ mersenne.seed(seed);
+ }
+ }
// returns a single random number based on a max number or range
this.number = function (options) {
@@ -28,7 +36,7 @@ function Random (faker) {
var max = options.max;
if (max >= 0) {
max += options.precision;
- }
+ }
var randomNumber = options.precision * Math.floor(
mersenne.rand(max / options.precision, options.min / options.precision));