Skip to content

Commit

Permalink
Implemented faker.seed method for randomization seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Dail authored and Brandon Dail committed Jul 15, 2015
1 parent a0465fc commit 40c13f2
Show file tree
Hide file tree
Showing 142 changed files with 2,785 additions and 2,001 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ As of version `v3.0.0` faker.js contains a super useful generator method `Faker.
**Example:**

``` js
console.log(faker.fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}'));
console.log(faker.fake(', '));
// outputs: "Marks, Dean Sr."
```

Expand Down
483 changes: 247 additions & 236 deletions build/build/faker.js

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions build/build/faker.min.js

Large diffs are not rendered by default.

57 changes: 34 additions & 23 deletions build/build/locales/de/faker.de.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ module["exports"] = Image;
*/

function Faker (opts) {

var self = this;

opts = opts || {};
Expand All @@ -837,20 +837,19 @@ function Faker (opts) {
var locales = self.locales || opts.locales || {};
var locale = self.locale || opts.locale || "en";
var localeFallback = self.localeFallback || opts.localeFallback || "en";

self.locales = locales;
self.locale = locale;
self.localeFallback = localeFallback;



self.definitions = {};

var Fake = require('./fake');
self.fake = new Fake(self).fake;

var Random = require('./random');
self.random = new Random(self);
// self.random = require('./random');
// self.random = require('./random');

var Helpers = require('./helpers');
self.helpers = new Helpers(self);
Expand Down Expand Up @@ -890,7 +889,7 @@ function Faker (opts) {
self.commerce = new Commerce(self);

// TODO: fix self.commerce = require('./commerce');

var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix", "title", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode"],
Expand Down Expand Up @@ -932,11 +931,16 @@ function Faker (opts) {
});
});
});



};

Faker.prototype.seed = function(value) {
var Random = require('./random');
this.seedValue = value;
this.random = new Random(this, this.seedValue);
}
module['exports'] = Faker;

},{"./address":1,"./commerce":2,"./company":3,"./date":4,"./fake":5,"./finance":6,"./hacker":7,"./helpers":8,"./image":9,"./internet":11,"./lorem":128,"./name":129,"./phone_number":130,"./random":131}],11:[function(require,module,exports){
var password_generator = require('../vendor/password-generator.js'),
random_ua = require('../vendor/user-agent');
Expand Down Expand Up @@ -2489,7 +2493,7 @@ module["exports"] = [

},{}],31:[function(require,module,exports){
module.exports=require(29)
},{"/Users/a/dev/faker.js/lib/locales/de/company/legal_form.js":29}],32:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/company/legal_form.js":29}],32:[function(require,module,exports){
var de = {};
module['exports'] = de;
de.title = "German";
Expand Down Expand Up @@ -5691,7 +5695,7 @@ module["exports"] = [

},{}],47:[function(require,module,exports){
module.exports=require(13)
},{"/Users/a/dev/faker.js/lib/locales/de/address/city.js":13}],48:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/address/city.js":13}],48:[function(require,module,exports){
module["exports"] = [
"North",
"East",
Expand Down Expand Up @@ -6272,7 +6276,7 @@ module["exports"] = [

},{}],56:[function(require,module,exports){
module.exports=require(55)
},{"/Users/a/dev/faker.js/lib/locales/en/address/postcode.js":55}],57:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/en/address/postcode.js":55}],57:[function(require,module,exports){
module["exports"] = [
"Apt. ###",
"Suite ###"
Expand Down Expand Up @@ -6902,7 +6906,7 @@ module["exports"] = [

},{}],73:[function(require,module,exports){
arguments[4][27][0].apply(exports,arguments)
},{"./formats":72,"/Users/a/dev/faker.js/lib/locales/de/cell_phone/index.js":27}],74:[function(require,module,exports){
},{"./formats":72,"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/cell_phone/index.js":27}],74:[function(require,module,exports){
module["exports"] = [
"red",
"green",
Expand Down Expand Up @@ -9788,7 +9792,7 @@ module["exports"] = [

},{}],111:[function(require,module,exports){
module.exports=require(34)
},{"/Users/a/dev/faker.js/lib/locales/de/internet/free_email.js":34}],112:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/internet/free_email.js":34}],112:[function(require,module,exports){
var internet = {};
module['exports'] = internet;
internet.free_email = require("./free_email");
Expand Down Expand Up @@ -10647,7 +10651,7 @@ module["exports"] = [

},{}],115:[function(require,module,exports){
module.exports=require(37)
},{"/Users/a/dev/faker.js/lib/locales/de/lorem/words.js":37}],116:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/lorem/words.js":37}],116:[function(require,module,exports){
module["exports"] = [
"Aaliyah",
"Aaron",
Expand Down Expand Up @@ -14300,7 +14304,7 @@ module["exports"] = [

},{}],124:[function(require,module,exports){
arguments[4][45][0].apply(exports,arguments)
},{"./formats":123,"/Users/a/dev/faker.js/lib/locales/de/phone_number/index.js":45}],125:[function(require,module,exports){
},{"./formats":123,"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de/phone_number/index.js":45}],125:[function(require,module,exports){
module["exports"] = [
"ants",
"bats",
Expand Down Expand Up @@ -14560,8 +14564,16 @@ module['exports'] = Phone;
},{}],131:[function(require,module,exports){
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) {

Expand All @@ -14588,7 +14600,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));
Expand Down Expand Up @@ -14750,7 +14762,7 @@ function MersenneTwister19937()
//c//mt[0]= s & 0xffffffff;
mt[0]= unsigned32(s & 0xffffffff);
for (mti=1; mti<N; mti++) {
mt[mti] =
mt[mti] =
//c//(1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
addition32(multiplication32(1812433253, unsigned32(mt[mti-1] ^ (mt[mti-1] >>> 30))), mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
Expand Down Expand Up @@ -14780,7 +14792,7 @@ function MersenneTwister19937()
//c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525))
//c// + init_key[j] + j; /* non linear */
mt[i] = addition32(addition32(unsigned32(mt[i] ^ multiplication32(unsigned32(mt[i-1] ^ (mt[i-1] >>> 30)), 1664525)), init_key[j]), j);
mt[i] =
mt[i] =
//c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
unsigned32(mt[i] & 0xffffffff);
i++; j++;
Expand Down Expand Up @@ -14932,7 +14944,6 @@ exports.seed_array = function(A) {
gen.init_by_array(A);
}


},{}],134:[function(require,module,exports){
/*
* password-generator
Expand Down
10 changes: 5 additions & 5 deletions build/build/locales/de/faker.de.min.js

Large diffs are not rendered by default.

53 changes: 32 additions & 21 deletions build/build/locales/de_AT/faker.de_AT.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ module["exports"] = Image;
*/

function Faker (opts) {

var self = this;

opts = opts || {};
Expand All @@ -837,20 +837,19 @@ function Faker (opts) {
var locales = self.locales || opts.locales || {};
var locale = self.locale || opts.locale || "en";
var localeFallback = self.localeFallback || opts.localeFallback || "en";

self.locales = locales;
self.locale = locale;
self.localeFallback = localeFallback;



self.definitions = {};

var Fake = require('./fake');
self.fake = new Fake(self).fake;

var Random = require('./random');
self.random = new Random(self);
// self.random = require('./random');
// self.random = require('./random');

var Helpers = require('./helpers');
self.helpers = new Helpers(self);
Expand Down Expand Up @@ -890,7 +889,7 @@ function Faker (opts) {
self.commerce = new Commerce(self);

// TODO: fix self.commerce = require('./commerce');

var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix", "title", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode"],
Expand Down Expand Up @@ -932,11 +931,16 @@ function Faker (opts) {
});
});
});



};

Faker.prototype.seed = function(value) {
var Random = require('./random');
this.seedValue = value;
this.random = new Random(this, this.seedValue);
}
module['exports'] = Faker;

},{"./address":1,"./commerce":2,"./company":3,"./date":4,"./fake":5,"./finance":6,"./hacker":7,"./helpers":8,"./image":9,"./internet":11,"./lorem":125,"./name":126,"./phone_number":127,"./random":128}],11:[function(require,module,exports){
var password_generator = require('../vendor/password-generator.js'),
random_ua = require('../vendor/user-agent');
Expand Down Expand Up @@ -1741,7 +1745,7 @@ module["exports"] = [

},{}],30:[function(require,module,exports){
module.exports=require(28)
},{"/Users/a/dev/faker.js/lib/locales/de_AT/company/legal_form.js":28}],31:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de_AT/company/legal_form.js":28}],31:[function(require,module,exports){
var de_AT = {};
module['exports'] = de_AT;
de_AT.title = "German (Austria)";
Expand Down Expand Up @@ -5275,7 +5279,7 @@ module["exports"] = [

},{}],53:[function(require,module,exports){
module.exports=require(52)
},{"/Users/a/dev/faker.js/lib/locales/en/address/postcode.js":52}],54:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/en/address/postcode.js":52}],54:[function(require,module,exports){
module["exports"] = [
"Apt. ###",
"Suite ###"
Expand Down Expand Up @@ -5905,7 +5909,7 @@ module["exports"] = [

},{}],70:[function(require,module,exports){
arguments[4][26][0].apply(exports,arguments)
},{"./formats":69,"/Users/a/dev/faker.js/lib/locales/de_AT/cell_phone/index.js":26}],71:[function(require,module,exports){
},{"./formats":69,"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de_AT/cell_phone/index.js":26}],71:[function(require,module,exports){
module["exports"] = [
"red",
"green",
Expand Down Expand Up @@ -8791,7 +8795,7 @@ module["exports"] = [

},{}],108:[function(require,module,exports){
module.exports=require(33)
},{"/Users/a/dev/faker.js/lib/locales/de_AT/internet/free_email.js":33}],109:[function(require,module,exports){
},{"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de_AT/internet/free_email.js":33}],109:[function(require,module,exports){
var internet = {};
module['exports'] = internet;
internet.free_email = require("./free_email");
Expand Down Expand Up @@ -13554,7 +13558,7 @@ module["exports"] = [

},{}],121:[function(require,module,exports){
arguments[4][42][0].apply(exports,arguments)
},{"./formats":120,"/Users/a/dev/faker.js/lib/locales/de_AT/phone_number/index.js":42}],122:[function(require,module,exports){
},{"./formats":120,"/Users/brandondail/.dev/Faker/faker.js/lib/locales/de_AT/phone_number/index.js":42}],122:[function(require,module,exports){
module["exports"] = [
"ants",
"bats",
Expand Down Expand Up @@ -13814,8 +13818,16 @@ module['exports'] = Phone;
},{}],128:[function(require,module,exports){
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) {

Expand All @@ -13842,7 +13854,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));
Expand Down Expand Up @@ -14004,7 +14016,7 @@ function MersenneTwister19937()
//c//mt[0]= s & 0xffffffff;
mt[0]= unsigned32(s & 0xffffffff);
for (mti=1; mti<N; mti++) {
mt[mti] =
mt[mti] =
//c//(1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
addition32(multiplication32(1812433253, unsigned32(mt[mti-1] ^ (mt[mti-1] >>> 30))), mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
Expand Down Expand Up @@ -14034,7 +14046,7 @@ function MersenneTwister19937()
//c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525))
//c// + init_key[j] + j; /* non linear */
mt[i] = addition32(addition32(unsigned32(mt[i] ^ multiplication32(unsigned32(mt[i-1] ^ (mt[i-1] >>> 30)), 1664525)), init_key[j]), j);
mt[i] =
mt[i] =
//c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
unsigned32(mt[i] & 0xffffffff);
i++; j++;
Expand Down Expand Up @@ -14186,7 +14198,6 @@ exports.seed_array = function(A) {
gen.init_by_array(A);
}


},{}],131:[function(require,module,exports){
/*
* password-generator
Expand Down
8 changes: 4 additions & 4 deletions build/build/locales/de_AT/faker.de_AT.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 40c13f2

Please sign in to comment.