3 // (c) 2013 Victor Quinn
4 // Chance may be freely distributed or modified under the MIT license.
9 var MAX_INT
= 9007199254740992;
10 var MIN_INT
= -MAX_INT
;
11 var NUMBERS
= '0123456789';
12 var CHARS_LOWER
= 'abcdefghijklmnopqrstuvwxyz';
13 var CHARS_UPPER
= CHARS_LOWER
.toUpperCase();
14 var HEX_POOL
= NUMBERS
+ "abcdef";
16 // Cached array helpers
17 var slice
= Array
.prototype.slice
;
20 function Chance (seed
) {
21 if (!(this instanceof Chance
)) {
22 return new Chance(seed
);
25 if (seed
!== undefined) {
26 // If we were passed a generator rather than a seed, use it.
27 if (typeof seed
=== 'function') {
34 // If no generator function was provided, use our MT
35 if (typeof this.random
=== 'undefined') {
36 this.mt
= this.mersenne_twister(seed
);
37 this.random = function () {
38 return this.mt
.random(this.seed
);
45 Chance
.prototype.VERSION
= "0.6.1";
47 // Random helper functions
48 function initOptions(options
, defaults
) {
49 options
|| (options
= {});
52 for (var i
in defaults
) {
53 if (typeof options
[i
] === 'undefined') {
54 options
[i
] = defaults
[i
];
62 function testRange(test
, errorMessage
) {
64 throw new RangeError(errorMessage
);
70 Chance
.prototype.bool = function (options
) {
72 // likelihood of success (true)
73 options
= initOptions(options
, {likelihood
: 50});
76 options
.likelihood
< 0 || options
.likelihood
> 100,
77 "Chance: Likelihood accepts values from 0 to 100."
80 return this.random() * 100 < options
.likelihood
;
83 Chance
.prototype.character = function (options
) {
84 options
= initOptions(options
);
86 var symbols
= "!@#$%^&*()[]",
90 options
.alpha
&& options
.symbols
,
91 "Chance: Cannot specify both alpha and symbols."
95 if (options
.casing
=== 'lower') {
96 letters
= CHARS_LOWER
;
97 } else if (options
.casing
=== 'upper') {
98 letters
= CHARS_UPPER
;
100 letters
= CHARS_LOWER
+ CHARS_UPPER
;
105 } else if (options
.alpha
) {
107 } else if (options
.symbols
) {
110 pool
= letters
+ NUMBERS
+ symbols
;
113 return pool
.charAt(this.natural({max
: (pool
.length
- 1)}));
116 // Note, wanted to use "float" or "double" but those are both JS reserved words.
118 // Note, fixed means N OR LESS digits after the decimal. This because
119 // It could be 14.9000 but in JavaScript, when this is cast as a number,
120 // the trailing zeroes are dropped. Left to the consumer if trailing zeroes are
122 Chance
.prototype.floating = function (options
) {
125 options
= initOptions(options
, {fixed
: 4});
126 var fixed
= Math
.pow(10, options
.fixed
);
129 options
.fixed
&& options
.precision
,
130 "Chance: Cannot specify both fixed and precision."
133 var max
= MAX_INT
/ fixed
;
137 options
.min
&& options
.fixed
&& options
.min
< min
,
138 "Chance: Min specified is out of range with fixed. Min should be, at least, " + min
141 options
.max
&& options
.fixed
&& options
.max
> max
,
142 "Chance: Max specified is out of range with fixed. Max should be, at most, " + max
145 options
= initOptions(options
, {min
: min
, max
: max
});
147 // Todo - Make this work!
148 // options.precision = (typeof options.precision !== "undefined") ? options.precision : false;
150 num
= this.integer({min
: options
.min
* fixed
, max
: options
.max
* fixed
});
151 var num_fixed
= (num
/ fixed
).toFixed(options
.fixed
);
153 return parseFloat(num_fixed
);
156 // NOTE the max and min are INCLUDED in the range. So:
158 // chance.natural({min: 1, max: 3});
160 // would return either 1, 2, or 3.
162 Chance
.prototype.integer = function (options
) {
164 // 9007199254740992 (2^53) is the max integer number in JavaScript
165 // See: http://vq.io/132sa2j
166 options
= initOptions(options
, {min
: MIN_INT
, max
: MAX_INT
});
168 testRange(options
.min
> options
.max
, "Chance: Min cannot be greater than Max.");
170 return Math
.floor(this.random() * (options
.max
- options
.min
+ 1) + options
.min
);
173 Chance
.prototype.natural = function (options
) {
174 options
= initOptions(options
, {min
: 0, max
: MAX_INT
});
175 return this.integer(options
);
178 Chance
.prototype.string = function (options
) {
179 options
= initOptions(options
);
181 var length
= options
.length
|| this.natural({min
: 5, max
: 20}),
183 text
= this.n(this.character
, length
, {pool
: pool
});
185 return text
.join("");
192 Chance
.prototype.capitalize = function (word
) {
193 return word
.charAt(0).toUpperCase() + word
.substr(1);
196 Chance
.prototype.mixin = function (obj
) {
197 for (var func_name
in obj
) {
198 Chance
.prototype[func_name
] = obj
[func_name
];
203 // Given a function that generates something random and a number of items to generate,
204 // return an array of items where none repeat.
205 Chance
.prototype.unique = function(fn
, num
, options
) {
206 options
= initOptions(options
, {
207 // Default comparator to check that val is not already in arr.
208 // Should return `false` if item not in array, `true` otherwise
209 comparator: function(arr
, val
) {
210 return arr
.indexOf(val
) !== -1;
214 var arr
= [], count
= 0, result
, MAX_DUPLICATES
= num
* 50, params
= slice
.call(arguments
, 2);
216 while (arr
.length
< num
) {
217 result
= fn
.apply(this, params
);
218 if (!options
.comparator(arr
, result
)) {
220 // reset count when unique found
224 if (++count
> MAX_DUPLICATES
) {
225 throw new RangeError("Chance: num is likely too large for sample set");
232 * Gives an array of n random terms
233 * @param fn the function that generates something random
234 * @param n number of terms to generate
235 * @param options options for the function fn.
236 * There can be more parameters after these. All additional parameters are provided to the given function
238 Chance
.prototype.n = function(fn
, n
, options
) {
239 var i
= n
|| 1, arr
= [], params
= slice
.call(arguments
, 2);
241 for (null; i
--; null) {
242 arr
.push(fn
.apply(this, params
));
248 // H/T to SO for this one: http://vq.io/OtUrZ5
249 Chance
.prototype.pad = function (number
, width
, pad
) {
250 // Default pad to 0 if none provided
252 // Convert number to a string
253 number
= number
+ '';
254 return number
.length
>= width
? number
: new Array(width
- number
.length
+ 1).join(pad
) + number
;
257 Chance
.prototype.pick = function (arr
, count
) {
258 if (!count
|| count
=== 1) {
259 return arr
[this.natural({max
: arr
.length
- 1})];
261 return this.shuffle(arr
).slice(0, count
);
265 Chance
.prototype.shuffle = function (arr
) {
266 var old_array
= arr
.slice(0),
269 length
= Number(old_array
.length
);
271 for (var i
= 0; i
< length
; i
++) {
272 // Pick a random index from the array
273 j
= this.natural({max
: old_array
.length
- 1});
274 // Add it to the new array
275 new_array
[i
] = old_array
[j
];
276 // Remove that element from the original array
277 old_array
.splice(j
, 1);
283 // Returns a single item from an array with relative weighting of odds
284 Chance
.prototype.weighted = function(arr
, weights
) {
285 if (arr
.length
!== weights
.length
) {
286 throw new RangeError("Chance: length of array and weights must match");
289 // If any of the weights are less than 1, we want to scale them up to whole
290 // numbers for the rest of this logic to work
291 if (weights
.some(function(weight
) { return weight
< 1; })) {
292 var min
= weights
.reduce(function(min
, weight
) {
293 return (weight
< min
) ? weight
: min
;
296 var scaling_factor
= 1 / min
;
298 weights
= weights
.map(function(weight
) {
299 return weight
* scaling_factor
;
303 var sum
= weights
.reduce(function(total
, weight
) {
304 return total
+ weight
;
308 var selected
= this.natural({ min
: 1, max
: sum
});
312 // Using some() here so we can bail as soon as we get our match
313 weights
.some(function(weight
, index
) {
314 if (selected
<= total
+ weight
) {
329 Chance
.prototype.paragraph = function (options
) {
330 options
= initOptions(options
);
332 var sentences
= options
.sentences
|| this.natural({min
: 3, max
: 7}),
333 sentence_array
= this.n(this.sentence
, sentences
);
335 return sentence_array
.join(' ');
338 // Could get smarter about this than generating random words and
339 // chaining them together. Such as: http://vq.io/1a5ceOh
340 Chance
.prototype.sentence = function (options
) {
341 options
= initOptions(options
);
343 var words
= options
.words
|| this.natural({min
: 12, max
: 18}),
344 text
, word_array
= this.n(this.word
, words
);
346 text
= word_array
.join(' ');
348 // Capitalize first letter of sentence, add period at end
349 text
= this.capitalize(text
) + '.';
354 Chance
.prototype.syllable = function (options
) {
355 options
= initOptions(options
);
357 var length
= options
.length
|| this.natural({min
: 2, max
: 3}),
358 consonants
= 'bcdfghjklmnprstvwz', // consonants except hard to speak ones
359 vowels
= 'aeiou', // vowels
360 all
= consonants
+ vowels
, // all
364 // I'm sure there's a more elegant way to do this, but this works
366 for (var i
= 0; i
< length
; i
++) {
368 // First character can be anything
369 chr
= this.character({pool
: all
});
370 } else if (consonants
.indexOf(chr
) === -1) {
371 // Last character was a vowel, now we want a consonant
372 chr
= this.character({pool
: consonants
});
374 // Last character was a consonant, now we want a vowel
375 chr
= this.character({pool
: vowels
});
384 Chance
.prototype.word = function (options
) {
385 options
= initOptions(options
);
388 options
.syllables
&& options
.length
,
389 "Chance: Cannot specify both syllables AND length."
392 var syllables
= options
.syllables
|| this.natural({min
: 1, max
: 3}),
395 if (options
.length
) {
396 // Either bound word by length
398 text
+= this.syllable();
399 } while (text
.length
< options
.length
);
400 text
= text
.substring(0, options
.length
);
402 // Or by number of syllables
403 for (var i
= 0; i
< syllables
; i
++) {
404 text
+= this.syllable();
414 Chance
.prototype.age = function (options
) {
415 options
= initOptions(options
);
418 switch (options
.type
) {
420 ageRange
= {min
: 1, max
: 12};
423 ageRange
= {min
: 13, max
: 19};
426 ageRange
= {min
: 18, max
: 65};
429 ageRange
= {min
: 65, max
: 100};
432 ageRange
= {min
: 1, max
: 100};
435 ageRange
= {min
: 18, max
: 65};
439 return this.natural(ageRange
);
442 Chance
.prototype.birthday = function (options
) {
443 options
= initOptions(options
, {
444 year
: (new Date().getFullYear() - this.age(options
))
447 return this.date(options
);
450 // CPF; ID to identify taxpayers in Brazil
451 Chance
.prototype.cpf = function () {
452 var n
= this.n(this.natural
, 9, { max
: 9 });
453 var d1
= n
[8]*2+n
[7]*3+n
[6]*4+n
[5]*5+n
[4]*6+n
[3]*7+n
[2]*8+n
[1]*9+n
[0]*10;
458 var d2
= d1
*2+n
[8]*3+n
[7]*4+n
[6]*5+n
[5]*6+n
[4]*7+n
[3]*8+n
[2]*9+n
[1]*10+n
[0]*11;
463 return ''+n
[0]+n
[1]+n
[2]+'.'+n
[3]+n
[4]+n
[5]+'.'+n
[6]+n
[7]+n
[8]+'-'+d1
+d2
;
466 Chance
.prototype.first = function (options
) {
467 options
= initOptions(options
, {gender
: this.gender()});
468 return this.pick(this.get("firstNames")[options
.gender
.toLowerCase()]);
471 Chance
.prototype.gender = function () {
472 return this.pick(['Male', 'Female']);
475 Chance
.prototype.last = function () {
476 return this.pick(this.get("lastNames"));
479 Chance
.prototype.name = function (options
) {
480 options
= initOptions(options
);
482 var first
= this.first(options
),
486 if (options
.middle
) {
487 name
= first
+ ' ' + this.first(options
) + ' ' + last
;
488 } else if (options
.middle_initial
) {
489 name
= first
+ ' ' + this.character({alpha
: true, casing
: 'upper'}) + '. ' + last
;
491 name
= first
+ ' ' + last
;
494 if (options
.prefix
) {
495 name
= this.prefix(options
) + ' ' + name
;
501 // Return the list of available name prefixes based on supplied gender.
502 Chance
.prototype.name_prefixes = function (gender
) {
503 gender
= gender
|| "all";
506 { name
: 'Doctor', abbreviation
: 'Dr.' }
509 if (gender
=== "male" || gender
=== "all") {
510 prefixes
.push({ name
: 'Mister', abbreviation
: 'Mr.' });
513 if (gender
=== "female" || gender
=== "all") {
514 prefixes
.push({ name
: 'Miss', abbreviation
: 'Miss' });
515 prefixes
.push({ name
: 'Misses', abbreviation
: 'Mrs.' });
521 // Alias for name_prefix
522 Chance
.prototype.prefix = function (options
) {
523 return this.name_prefix(options
);
526 Chance
.prototype.name_prefix = function (options
) {
527 options
= initOptions(options
, { gender
: "all" });
528 return options
.full
?
529 this.pick(this.name_prefixes(options
.gender
)).name
:
530 this.pick(this.name_prefixes(options
.gender
)).abbreviation
;
533 Chance
.prototype.ssn = function (options
) {
534 options
= initOptions(options
, {ssnFour
: false, dashes
: true});
535 var ssn_pool
= "1234567890",
537 dash
= options
.dashes
? '-' : '';
539 if(!options
.ssnFour
) {
540 ssn
= this.string({pool
: ssn_pool
, length
: 3}) + dash
+
541 this.string({pool
: ssn_pool
, length
: 2}) + dash
+
542 this.string({pool
: ssn_pool
, length
: 4});
544 ssn
= this.string({pool
: ssn_pool
, length
: 4});
554 Chance
.prototype.apple_token = function (options
) {
555 return this.string({ pool
: "abcdef1234567890", length
: 64 });
558 Chance
.prototype.color = function (options
) {
559 function gray(value
, delimiter
) {
560 return [value
, value
, value
].join(delimiter
|| '');
563 options
= initOptions(options
, {format
: this.pick(['hex', 'shorthex', 'rgb']), grayscale
: false});
564 var isGrayscale
= options
.grayscale
;
566 if (options
.format
=== 'hex') {
567 return '#' + (isGrayscale
? gray(this.hash({length
: 2})) : this.hash({length
: 6}));
570 if (options
.format
=== 'shorthex') {
571 return '#' + (isGrayscale
? gray(this.hash({length
: 1})) : this.hash({length
: 3}));
574 if (options
.format
=== 'rgb') {
576 return 'rgb(' + gray(this.natural({max
: 255}), ',') + ')';
578 return 'rgb(' + this.natural({max
: 255}) + ',' + this.natural({max
: 255}) + ',' + this.natural({max
: 255}) + ')';
582 throw new Error('Invalid format provided. Please provide one of "hex", "shorthex", or "rgb"');
585 Chance
.prototype.domain = function (options
) {
586 options
= initOptions(options
);
587 return this.word() + '.' + (options
.tld
|| this.tld());
590 Chance
.prototype.email = function (options
) {
591 options
= initOptions(options
);
592 return this.word({length
: options
.length
}) + '@' + (options
.domain
|| this.domain());
595 Chance
.prototype.fbid = function () {
596 return parseInt('10000' + this.natural({max
: 100000000000}), 10);
599 Chance
.prototype.google_analytics = function () {
600 var account
= this.pad(this.natural({max
: 999999}), 6);
601 var property
= this.pad(this.natural({max
: 99}), 2);
603 return 'UA-' + account
+ '-' + property
;
606 Chance
.prototype.hashtag = function () {
607 return '#' + this.word();
610 Chance
.prototype.ip = function () {
611 // Todo: This could return some reserved IPs. See http://vq.io/137dgYy
612 // this should probably be updated to account for that rare as it may be
613 return this.natural({max
: 255}) + '.' +
614 this.natural({max
: 255}) + '.' +
615 this.natural({max
: 255}) + '.' +
616 this.natural({max
: 255});
619 Chance
.prototype.ipv6 = function () {
620 var ip_addr
= this.n(this.hash
, 8, {length
: 4});
622 return ip_addr
.join(":");
625 Chance
.prototype.klout = function () {
626 return this.natural({min
: 1, max
: 99});
629 Chance
.prototype.tlds = function () {
630 return ['com', 'org', 'edu', 'gov', 'co.uk', 'net', 'io'];
633 Chance
.prototype.tld = function () {
634 return this.pick(this.tlds());
637 Chance
.prototype.twitter = function () {
638 return '@' + this.word();
645 Chance
.prototype.address = function (options
) {
646 options
= initOptions(options
);
647 return this.natural({min
: 5, max
: 2000}) + ' ' + this.street(options
);
650 Chance
.prototype.altitude = function (options
) {
651 options
= initOptions(options
, {fixed
: 5, max
: 8848});
652 return this.floating({min
: 0, max
: options
.max
, fixed
: options
.fixed
});
655 Chance
.prototype.areacode = function (options
) {
656 options
= initOptions(options
, {parens
: true});
657 // Don't want area codes to start with 1, or have a 9 as the second digit
658 var areacode
= this.natural({min
: 2, max
: 9}).toString() +
659 this.natural({min
: 0, max
: 8}).toString() +
660 this.natural({min
: 0, max
: 9}).toString();
662 return options
.parens
? '(' + areacode
+ ')' : areacode
;
665 Chance
.prototype.city = function () {
666 return this.capitalize(this.word({syllables
: 3}));
669 Chance
.prototype.coordinates = function (options
) {
670 options
= initOptions(options
);
671 return this.latitude(options
) + ', ' + this.longitude(options
);
674 Chance
.prototype.depth = function (options
) {
675 options
= initOptions(options
, {fixed
: 5, min
: -2550});
676 return this.floating({min
: options
.min
, max
: 0, fixed
: options
.fixed
});
679 Chance
.prototype.geohash = function (options
) {
680 options
= initOptions(options
, { length
: 7 });
681 return this.string({ length
: options
.length
, pool
: '0123456789bcdefghjkmnpqrstuvwxyz' });
684 Chance
.prototype.geojson = function (options
) {
685 options
= initOptions(options
);
686 return this.latitude(options
) + ', ' + this.longitude(options
) + ', ' + this.altitude(options
);
689 Chance
.prototype.latitude = function (options
) {
690 options
= initOptions(options
, {fixed
: 5, min
: -90, max
: 90});
691 return this.floating({min
: options
.min
, max
: options
.max
, fixed
: options
.fixed
});
694 Chance
.prototype.longitude = function (options
) {
695 options
= initOptions(options
, {fixed
: 5, min
: -180, max
: 180});
696 return this.floating({min
: options
.min
, max
: options
.max
, fixed
: options
.fixed
});
699 Chance
.prototype.phone = function (options
) {
700 options
= initOptions(options
, {formatted
: true});
701 if (!options
.formatted
) {
702 options
.parens
= false;
704 var areacode
= this.areacode(options
).toString();
705 var exchange
= this.natural({min
: 2, max
: 9}).toString() +
706 this.natural({min
: 0, max
: 9}).toString() +
707 this.natural({min
: 0, max
: 9}).toString();
709 var subscriber
= this.natural({min
: 1000, max
: 9999}).toString(); // this could be random [0-9]{4}
711 return options
.formatted
? areacode
+ ' ' + exchange
+ '-' + subscriber
: areacode
+ exchange
+ subscriber
;
714 Chance
.prototype.postal = function () {
716 var pd
= this.character({pool
: "XVTSRPNKLMHJGECBA"});
717 // Forward Sortation Area (FSA)
718 var fsa
= pd
+ this.natural({max
: 9}) + this.character({alpha
: true, casing
: "upper"});
719 // Local Delivery Unut (LDU)
720 var ldu
= this.natural({max
: 9}) + this.character({alpha
: true, casing
: "upper"}) + this.natural({max
: 9});
722 return fsa
+ " " + ldu
;
725 Chance
.prototype.provinces = function () {
726 return this.get("provinces");
729 Chance
.prototype.province = function (options
) {
730 return (options
&& options
.full
) ?
731 this.pick(this.provinces()).name
:
732 this.pick(this.provinces()).abbreviation
;
735 Chance
.prototype.state = function (options
) {
736 return (options
&& options
.full
) ?
737 this.pick(this.states(options
)).name
:
738 this.pick(this.states(options
)).abbreviation
;
741 Chance
.prototype.states = function (options
) {
742 options
= initOptions(options
);
745 us_states_and_dc
= this.get("us_states_and_dc"),
746 territories
= this.get("territories"),
747 armed_forces
= this.get("armed_forces");
749 states
= us_states_and_dc
;
751 if (options
.territories
) {
752 states
= states
.concat(territories
);
754 if (options
.armed_forces
) {
755 states
= states
.concat(armed_forces
);
761 Chance
.prototype.street = function (options
) {
762 options
= initOptions(options
);
764 var street
= this.word({syllables
: 2});
765 street
= this.capitalize(street
);
767 street
+= options
.short_suffix
?
768 this.street_suffix().abbreviation
:
769 this.street_suffix().name
;
773 Chance
.prototype.street_suffix = function () {
774 return this.pick(this.street_suffixes());
777 Chance
.prototype.street_suffixes = function () {
778 // These are the most common suffixes.
779 return this.get("street_suffixes");
782 // Note: only returning US zip codes, internationalization will be a whole
783 // other beast to tackle at some point.
784 Chance
.prototype.zip = function (options
) {
785 var zip
= this.n(this.natural
, 5, {max
: 9});
787 if (options
&& options
.plusfour
=== true) {
789 zip
= zip
.concat(this.n(this.natural
, 4, {max
: 9}));
795 // -- End Location --
799 Chance
.prototype.ampm = function () {
800 return this.bool() ? 'am' : 'pm';
803 Chance
.prototype.date = function (options
) {
804 var m
= this.month({raw
: true}),
807 options
= initOptions(options
, {
808 year
: parseInt(this.year(), 10),
809 // Necessary to subtract 1 because Date() 0-indexes month but not day or year
811 month
: m
.numeric
- 1,
812 day
: this.natural({min
: 1, max
: m
.days
}),
814 minute
: this.minute(),
815 second
: this.second(),
816 millisecond
: this.millisecond(),
821 var date
= new Date(options
.year
, options
.month
, options
.day
, options
.hour
, options
.minute
, options
.second
, options
.millisecond
);
823 if (options
.american
) {
824 // Adding 1 to the month is necessary because Date() 0-indexes
825 // months but not day for some odd reason.
826 date_string
= (date
.getMonth() + 1) + '/' + date
.getDate() + '/' + date
.getFullYear();
828 date_string
= date
.getDate() + '/' + (date
.getMonth() + 1) + '/' + date
.getFullYear();
831 return options
.string
? date_string
: date
;
834 Chance
.prototype.hammertime = function (options
) {
835 return this.date(options
).getTime();
838 Chance
.prototype.hour = function (options
) {
839 options
= initOptions(options
);
840 var max
= options
.twentyfour
? 24 : 12;
841 return this.natural({min
: 1, max
: max
});
844 Chance
.prototype.millisecond = function () {
845 return this.natural({max
: 999});
848 Chance
.prototype.minute
= Chance
.prototype.second = function () {
849 return this.natural({max
: 59});
852 Chance
.prototype.month = function (options
) {
853 options
= initOptions(options
);
854 var month
= this.pick(this.months());
855 return options
.raw
? month
: month
.name
;
858 Chance
.prototype.months = function () {
859 return this.get("months");
862 Chance
.prototype.second = function () {
863 return this.natural({max
: 59});
866 Chance
.prototype.timestamp = function () {
867 return this.natural({min
: 1, max
: parseInt(new Date().getTime() / 1000, 10)});
870 Chance
.prototype.year = function (options
) {
871 // Default to current year as min if none specified
872 options
= initOptions(options
, {min
: new Date().getFullYear()});
874 // Default to one century after current year as max if none specified
875 options
.max
= (typeof options
.max
!== "undefined") ? options
.max
: options
.min
+ 100;
877 return this.natural(options
).toString();
884 Chance
.prototype.cc = function (options
) {
885 options
= initOptions(options
);
887 var type
, number
, to_generate
;
889 type
= (options
.type
) ?
890 this.cc_type({ name
: options
.type
, raw
: true }) :
891 this.cc_type({ raw
: true });
893 number
= type
.prefix
.split("");
894 to_generate
= type
.length
- type
.prefix
.length
- 1;
896 // Generates n - 1 digits
897 number
= number
.concat(this.n(this.integer
, to_generate
, {min
: 0, max
: 9}));
899 // Generates the last digit according to Luhn algorithm
900 number
.push(this.luhn_calculate(number
.join("")));
902 return number
.join("");
905 Chance
.prototype.cc_types = function () {
906 // http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
907 return this.get("cc_types");
910 Chance
.prototype.cc_type = function (options
) {
911 options
= initOptions(options
);
912 var types
= this.cc_types(),
916 for (var i
= 0; i
< types
.length
; i
++) {
917 // Accept either name or short_name to specify card type
918 if (types
[i
].name
=== options
.name
|| types
[i
].short_name
=== options
.name
) {
924 throw new Error("Credit card type '" + options
.name
+ "'' is not supported");
927 type
= this.pick(types
);
930 return options
.raw
? type
: type
.name
;
933 //return all world currency by ISO 4217
934 Chance
.prototype.currency_types = function () {
935 return this.get("currency_types");
938 //return random world currency by ISO 4217
939 Chance
.prototype.currency = function () {
940 return this.pick(this.currency_types());
943 //Return random correct currency exchange pair (e.g. EUR/USD) or array of currency code
944 Chance
.prototype.currency_pair = function (returnAsString
) {
945 var currencies
= this.unique(this.currency
, 2, {
946 comparator: function(arr
, val
) {
948 return arr
.reduce(function(acc
, item
) {
949 // If a match has been found, short circuit check and just return
950 return acc
|| (item
.code
=== val
.code
);
955 if (returnAsString
) {
956 return currencies
[0] + '/' + currencies
[1];
962 Chance
.prototype.dollar = function (options
) {
963 // By default, a somewhat more sane max for dollar than all available numbers
964 options
= initOptions(options
, {max
: 10000, min
: 0});
966 var dollar
= this.floating({min
: options
.min
, max
: options
.max
, fixed
: 2}).toString(),
967 cents
= dollar
.split('.')[1];
969 if (cents
=== undefined) {
971 } else if (cents
.length
< 2) {
972 dollar
= dollar
+ '0';
976 return '-$' + dollar
.replace('-', '');
982 Chance
.prototype.exp = function (options
) {
983 options
= initOptions(options
);
986 exp
.year
= this.exp_year();
988 // If the year is this year, need to ensure month is greater than the
989 // current month or this expiration will not be valid
990 if (exp
.year
=== (new Date().getFullYear())) {
991 exp
.month
= this.exp_month({future
: true});
993 exp
.month
= this.exp_month();
996 return options
.raw
? exp
: exp
.month
+ '/' + exp
.year
;
999 Chance
.prototype.exp_month = function (options
) {
1000 options
= initOptions(options
);
1001 var month
, month_int
,
1002 curMonth
= new Date().getMonth();
1004 if (options
.future
) {
1006 month
= this.month({raw
: true}).numeric
;
1007 month_int
= parseInt(month
, 10);
1008 } while (month_int
< curMonth
);
1010 month
= this.month({raw
: true}).numeric
;
1016 Chance
.prototype.exp_year = function () {
1017 return this.year({max
: new Date().getFullYear() + 10});
1022 // -- Miscellaneous --
1024 // Dice - For all the board game geeks out there, myself included ;)
1025 function diceFn (range
) {
1026 return function () {
1027 return this.natural(range
);
1030 Chance
.prototype.d4
= diceFn({min
: 1, max
: 4});
1031 Chance
.prototype.d6
= diceFn({min
: 1, max
: 6});
1032 Chance
.prototype.d8
= diceFn({min
: 1, max
: 8});
1033 Chance
.prototype.d10
= diceFn({min
: 1, max
: 10});
1034 Chance
.prototype.d12
= diceFn({min
: 1, max
: 12});
1035 Chance
.prototype.d20
= diceFn({min
: 1, max
: 20});
1036 Chance
.prototype.d30
= diceFn({min
: 1, max
: 30});
1037 Chance
.prototype.d100
= diceFn({min
: 1, max
: 100});
1039 Chance
.prototype.rpg = function (thrown
, options
) {
1040 options
= initOptions(options
);
1041 if (thrown
=== null) {
1042 throw new Error("A type of die roll must be included");
1044 var bits
= thrown
.toLowerCase().split("d"),
1047 if (bits
.length
!== 2 || !parseInt(bits
[0], 10) || !parseInt(bits
[1], 10)) {
1048 throw new Error("Invalid format provided. Please provide #d# where the first # is the number of dice to roll, the second # is the max of each die");
1050 for (var i
= bits
[0]; i
> 0; i
--) {
1051 rolls
[i
- 1] = this.natural({min
: 1, max
: bits
[1]});
1053 return (typeof options
.sum
!== 'undefined' && options
.sum
) ? rolls
.reduce(function (p
, c
) { return p
+ c
; }) : rolls
;
1058 Chance
.prototype.guid = function (options
) {
1059 options
= initOptions(options
, { version
: 5 });
1061 var guid_pool
= "abcdef1234567890",
1062 variant_pool
= "ab89",
1063 guid
= this.string({ pool
: guid_pool
, length
: 8 }) + '-' +
1064 this.string({ pool
: guid_pool
, length
: 4 }) + '-' +
1067 this.string({ pool
: guid_pool
, length
: 3 }) + '-' +
1069 this.string({ pool
: variant_pool
, length
: 1 }) +
1070 this.string({ pool
: guid_pool
, length
: 3 }) + '-' +
1071 this.string({ pool
: guid_pool
, length
: 12 });
1076 Chance
.prototype.hash = function (options
) {
1077 options
= initOptions(options
, {length
: 40, casing
: 'lower'});
1078 var pool
= options
.casing
=== 'upper' ? HEX_POOL
.toUpperCase() : HEX_POOL
;
1079 return this.string({pool
: pool
, length
: options
.length
});
1082 Chance
.prototype.luhn_check = function (num
) {
1083 var str
= num
.toString();
1084 var checkDigit
= +str
.substring(str
.length
- 1);
1085 return checkDigit
=== this.luhn_calculate(+str
.substring(0, str
.length
- 1));
1088 Chance
.prototype.luhn_calculate = function (num
) {
1089 var digits
= num
.toString().split("").reverse();
1093 for (var i
= 0, l
= digits
.length
; l
> i
; ++i
) {
1103 return (sum
* 9) % 10;
1110 "male": ["James", "John", "Robert", "Michael", "William", "David", "Richard", "Joseph", "Charles", "Thomas", "Christopher", "Daniel", "Matthew", "George", "Donald", "Anthony", "Paul", "Mark", "Edward", "Steven", "Kenneth", "Andrew", "Brian", "Joshua", "Kevin", "Ronald", "Timothy", "Jason", "Jeffrey", "Frank", "Gary", "Ryan", "Nicholas", "Eric", "Stephen", "Jacob", "Larry", "Jonathan", "Scott", "Raymond", "Justin", "Brandon", "Gregory", "Samuel", "Benjamin", "Patrick", "Jack", "Henry", "Walter", "Dennis", "Jerry", "Alexander", "Peter", "Tyler", "Douglas", "Harold", "Aaron", "Jose", "Adam", "Arthur", "Zachary", "Carl", "Nathan", "Albert", "Kyle", "Lawrence", "Joe", "Willie", "Gerald", "Roger", "Keith", "Jeremy", "Terry", "Harry", "Ralph", "Sean", "Jesse", "Roy", "Louis", "Billy", "Austin", "Bruce", "Eugene", "Christian", "Bryan", "Wayne", "Russell", "Howard", "Fred", "Ethan", "Jordan", "Philip", "Alan", "Juan", "Randy", "Vincent", "Bobby", "Dylan", "Johnny", "Phillip", "Victor", "Clarence", "Ernest", "Martin", "Craig", "Stanley", "Shawn", "Travis", "Bradley", "Leonard", "Earl", "Gabriel", "Jimmy", "Francis", "Todd", "Noah", "Danny", "Dale", "Cody", "Carlos", "Allen", "Frederick", "Logan", "Curtis", "Alex", "Joel", "Luis", "Norman", "Marvin", "Glenn", "Tony", "Nathaniel", "Rodney", "Melvin", "Alfred", "Steve", "Cameron", "Chad", "Edwin", "Caleb", "Evan", "Antonio", "Lee", "Herbert", "Jeffery", "Isaac", "Derek", "Ricky", "Marcus", "Theodore", "Elijah", "Luke", "Jesus", "Eddie", "Troy", "Mike", "Dustin", "Ray", "Adrian", "Bernard", "Leroy", "Angel", "Randall", "Wesley", "Ian", "Jared", "Mason", "Hunter", "Calvin", "Oscar", "Clifford", "Jay", "Shane", "Ronnie", "Barry", "Lucas", "Corey", "Manuel", "Leo", "Tommy", "Warren", "Jackson", "Isaiah", "Connor", "Don", "Dean", "Jon", "Julian", "Miguel", "Bill", "Lloyd", "Charlie", "Mitchell", "Leon", "Jerome", "Darrell", "Jeremiah", "Alvin", "Brett", "Seth", "Floyd", "Jim", "Blake", "Micheal", "Gordon", "Trevor", "Lewis", "Erik", "Edgar", "Vernon", "Devin", "Gavin", "Jayden", "Chris", "Clyde", "Tom", "Derrick", "Mario", "Brent", "Marc", "Herman", "Chase", "Dominic", "Ricardo", "Franklin", "Maurice", "Max", "Aiden", "Owen", "Lester", "Gilbert", "Elmer", "Gene", "Francisco", "Glen", "Cory", "Garrett", "Clayton", "Sam", "Jorge", "Chester", "Alejandro", "Jeff", "Harvey", "Milton", "Cole", "Ivan", "Andre", "Duane", "Landon"],
1111 "female": ["Mary", "Emma", "Elizabeth", "Minnie", "Margaret", "Ida", "Alice", "Bertha", "Sarah", "Annie", "Clara", "Ella", "Florence", "Cora", "Martha", "Laura", "Nellie", "Grace", "Carrie", "Maude", "Mabel", "Bessie", "Jennie", "Gertrude", "Julia", "Hattie", "Edith", "Mattie", "Rose", "Catherine", "Lillian", "Ada", "Lillie", "Helen", "Jessie", "Louise", "Ethel", "Lula", "Myrtle", "Eva", "Frances", "Lena", "Lucy", "Edna", "Maggie", "Pearl", "Daisy", "Fannie", "Josephine", "Dora", "Rosa", "Katherine", "Agnes", "Marie", "Nora", "May", "Mamie", "Blanche", "Stella", "Ellen", "Nancy", "Effie", "Sallie", "Nettie", "Della", "Lizzie", "Flora", "Susie", "Maud", "Mae", "Etta", "Harriet", "Sadie", "Caroline", "Katie", "Lydia", "Elsie", "Kate", "Susan", "Mollie", "Alma", "Addie", "Georgia", "Eliza", "Lulu", "Nannie", "Lottie", "Amanda", "Belle", "Charlotte", "Rebecca", "Ruth", "Viola", "Olive", "Amelia", "Hannah", "Jane", "Virginia", "Emily", "Matilda", "Irene", "Kathryn", "Esther", "Willie", "Henrietta", "Ollie", "Amy", "Rachel", "Sara", "Estella", "Theresa", "Augusta", "Ora", "Pauline", "Josie", "Lola", "Sophia", "Leona", "Anne", "Mildred", "Ann", "Beulah", "Callie", "Lou", "Delia", "Eleanor", "Barbara", "Iva", "Louisa", "Maria", "Mayme", "Evelyn", "Estelle", "Nina", "Betty", "Marion", "Bettie", "Dorothy", "Luella", "Inez", "Lela", "Rosie", "Allie", "Millie", "Janie", "Cornelia", "Victoria", "Ruby", "Winifred", "Alta", "Celia", "Christine", "Beatrice", "Birdie", "Harriett", "Mable", "Myra", "Sophie", "Tillie", "Isabel", "Sylvia", "Carolyn", "Isabelle", "Leila", "Sally", "Ina", "Essie", "Bertie", "Nell", "Alberta", "Katharine", "Lora", "Rena", "Mina", "Rhoda", "Mathilda", "Abbie", "Eula", "Dollie", "Hettie", "Eunice", "Fanny", "Ola", "Lenora", "Adelaide", "Christina", "Lelia", "Nelle", "Sue", "Johanna", "Lilly", "Lucinda", "Minerva", "Lettie", "Roxie", "Cynthia", "Helena", "Hilda", "Hulda", "Bernice", "Genevieve", "Jean", "Cordelia", "Marian", "Francis", "Jeanette", "Adeline", "Gussie", "Leah", "Lois", "Lura", "Mittie", "Hallie", "Isabella", "Olga", "Phoebe", "Teresa", "Hester", "Lida", "Lina", "Winnie", "Claudia", "Marguerite", "Vera", "Cecelia", "Bess", "Emilie", "John", "Rosetta", "Verna", "Myrtie", "Cecilia", "Elva", "Olivia", "Ophelia", "Georgie", "Elnora", "Violet", "Adele", "Lily", "Linnie", "Loretta", "Madge", "Polly", "Virgie", "Eugenia", "Lucile", "Lucille", "Mabelle", "Rosalie"]
1114 lastNames
: ['Smith', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor', 'Anderson', 'Thomas', 'Jackson', 'White', 'Harris', 'Martin', 'Thompson', 'Garcia', 'Martinez', 'Robinson', 'Clark', 'Rodriguez', 'Lewis', 'Lee', 'Walker', 'Hall', 'Allen', 'Young', 'Hernandez', 'King', 'Wright', 'Lopez', 'Hill', 'Scott', 'Green', 'Adams', 'Baker', 'Gonzalez', 'Nelson', 'Carter', 'Mitchell', 'Perez', 'Roberts', 'Turner', 'Phillips', 'Campbell', 'Parker', 'Evans', 'Edwards', 'Collins', 'Stewart', 'Sanchez', 'Morris', 'Rogers', 'Reed', 'Cook', 'Morgan', 'Bell', 'Murphy', 'Bailey', 'Rivera', 'Cooper', 'Richardson', 'Cox', 'Howard', 'Ward', 'Torres', 'Peterson', 'Gray', 'Ramirez', 'James', 'Watson', 'Brooks', 'Kelly', 'Sanders', 'Price', 'Bennett', 'Wood', 'Barnes', 'Ross', 'Henderson', 'Coleman', 'Jenkins', 'Perry', 'Powell', 'Long', 'Patterson', 'Hughes', 'Flores', 'Washington', 'Butler', 'Simmons', 'Foster', 'Gonzales', 'Bryant', 'Alexander', 'Russell', 'Griffin', 'Diaz', 'Hayes', 'Myers', 'Ford', 'Hamilton', 'Graham', 'Sullivan', 'Wallace', 'Woods', 'Cole', 'West', 'Jordan', 'Owens', 'Reynolds', 'Fisher', 'Ellis', 'Harrison', 'Gibson', 'McDonald', 'Cruz', 'Marshall', 'Ortiz', 'Gomez', 'Murray', 'Freeman', 'Wells', 'Webb', 'Simpson', 'Stevens', 'Tucker', 'Porter', 'Hunter', 'Hicks', 'Crawford', 'Henry', 'Boyd', 'Mason', 'Morales', 'Kennedy', 'Warren', 'Dixon', 'Ramos', 'Reyes', 'Burns', 'Gordon', 'Shaw', 'Holmes', 'Rice', 'Robertson', 'Hunt', 'Black', 'Daniels', 'Palmer', 'Mills', 'Nichols', 'Grant', 'Knight', 'Ferguson', 'Rose', 'Stone', 'Hawkins', 'Dunn', 'Perkins', 'Hudson', 'Spencer', 'Gardner', 'Stephens', 'Payne', 'Pierce', 'Berry', 'Matthews', 'Arnold', 'Wagner', 'Willis', 'Ray', 'Watkins', 'Olson', 'Carroll', 'Duncan', 'Snyder', 'Hart', 'Cunningham', 'Bradley', 'Lane', 'Andrews', 'Ruiz', 'Harper', 'Fox', 'Riley', 'Armstrong', 'Carpenter', 'Weaver', 'Greene', 'Lawrence', 'Elliott', 'Chavez', 'Sims', 'Austin', 'Peters', 'Kelley', 'Franklin', 'Lawson', 'Fields', 'Gutierrez', 'Ryan', 'Schmidt', 'Carr', 'Vasquez', 'Castillo', 'Wheeler', 'Chapman', 'Oliver', 'Montgomery', 'Richards', 'Williamson', 'Johnston', 'Banks', 'Meyer', 'Bishop', 'McCoy', 'Howell', 'Alvarez', 'Morrison', 'Hansen', 'Fernandez', 'Garza', 'Harvey', 'Little', 'Burton', 'Stanley', 'Nguyen', 'George', 'Jacobs', 'Reid', 'Kim', 'Fuller', 'Lynch', 'Dean', 'Gilbert', 'Garrett', 'Romero', 'Welch', 'Larson', 'Frazier', 'Burke', 'Hanson', 'Day', 'Mendoza', 'Moreno', 'Bowman', 'Medina', 'Fowler', 'Brewer', 'Hoffman', 'Carlson', 'Silva', 'Pearson', 'Holland', 'Douglas', 'Fleming', 'Jensen', 'Vargas', 'Byrd', 'Davidson', 'Hopkins', 'May', 'Terry', 'Herrera', 'Wade', 'Soto', 'Walters', 'Curtis', 'Neal', 'Caldwell', 'Lowe', 'Jennings', 'Barnett', 'Graves', 'Jimenez', 'Horton', 'Shelton', 'Barrett', 'Obrien', 'Castro', 'Sutton', 'Gregory', 'McKinney', 'Lucas', 'Miles', 'Craig', 'Rodriquez', 'Chambers', 'Holt', 'Lambert', 'Fletcher', 'Watts', 'Bates', 'Hale', 'Rhodes', 'Pena', 'Beck', 'Newman', 'Haynes', 'McDaniel', 'Mendez', 'Bush', 'Vaughn', 'Parks', 'Dawson', 'Santiago', 'Norris', 'Hardy', 'Love', 'Steele', 'Curry', 'Powers', 'Schultz', 'Barker', 'Guzman', 'Page', 'Munoz', 'Ball', 'Keller', 'Chandler', 'Weber', 'Leonard', 'Walsh', 'Lyons', 'Ramsey', 'Wolfe', 'Schneider', 'Mullins', 'Benson', 'Sharp', 'Bowen', 'Daniel', 'Barber', 'Cummings', 'Hines', 'Baldwin', 'Griffith', 'Valdez', 'Hubbard', 'Salazar', 'Reeves', 'Warner', 'Stevenson', 'Burgess', 'Santos', 'Tate', 'Cross', 'Garner', 'Mann', 'Mack', 'Moss', 'Thornton', 'Dennis', 'McGee', 'Farmer', 'Delgado', 'Aguilar', 'Vega', 'Glover', 'Manning', 'Cohen', 'Harmon', 'Rodgers', 'Robbins', 'Newton', 'Todd', 'Blair', 'Higgins', 'Ingram', 'Reese', 'Cannon', 'Strickland', 'Townsend', 'Potter', 'Goodwin', 'Walton', 'Rowe', 'Hampton', 'Ortega', 'Patton', 'Swanson', 'Joseph', 'Francis', 'Goodman', 'Maldonado', 'Yates', 'Becker', 'Erickson', 'Hodges', 'Rios', 'Conner', 'Adkins', 'Webster', 'Norman', 'Malone', 'Hammond', 'Flowers', 'Cobb', 'Moody', 'Quinn', 'Blake', 'Maxwell', 'Pope', 'Floyd', 'Osborne', 'Paul', 'McCarthy', 'Guerrero', 'Lindsey', 'Estrada', 'Sandoval', 'Gibbs', 'Tyler', 'Gross', 'Fitzgerald', 'Stokes', 'Doyle', 'Sherman', 'Saunders', 'Wise', 'Colon', 'Gill', 'Alvarado', 'Greer', 'Padilla', 'Simon', 'Waters', 'Nunez', 'Ballard', 'Schwartz', 'McBride', 'Houston', 'Christensen', 'Klein', 'Pratt', 'Briggs', 'Parsons', 'McLaughlin', 'Zimmerman', 'French', 'Buchanan', 'Moran', 'Copeland', 'Roy', 'Pittman', 'Brady', 'McCormick', 'Holloway', 'Brock', 'Poole', 'Frank', 'Logan', 'Owen', 'Bass', 'Marsh', 'Drake', 'Wong', 'Jefferson', 'Park', 'Morton', 'Abbott', 'Sparks', 'Patrick', 'Norton', 'Huff', 'Clayton', 'Massey', 'Lloyd', 'Figueroa', 'Carson', 'Bowers', 'Roberson', 'Barton', 'Tran', 'Lamb', 'Harrington', 'Casey', 'Boone', 'Cortez', 'Clarke', 'Mathis', 'Singleton', 'Wilkins', 'Cain', 'Bryan', 'Underwood', 'Hogan', 'McKenzie', 'Collier', 'Luna', 'Phelps', 'McGuire', 'Allison', 'Bridges', 'Wilkerson', 'Nash', 'Summers', 'Atkins'],
1117 {name
: 'Alberta', abbreviation
: 'AB'},
1118 {name
: 'British Columbia', abbreviation
: 'BC'},
1119 {name
: 'Manitoba', abbreviation
: 'MB'},
1120 {name
: 'New Brunswick', abbreviation
: 'NB'},
1121 {name
: 'Newfoundland and Labrador', abbreviation
: 'NL'},
1122 {name
: 'Nova Scotia', abbreviation
: 'NS'},
1123 {name
: 'Ontario', abbreviation
: 'ON'},
1124 {name
: 'Prince Edward Island', abbreviation
: 'PE'},
1125 {name
: 'Quebec', abbreviation
: 'QC'},
1126 {name
: 'Saskatchewan', abbreviation
: 'SK'},
1128 // The case could be made that the following are not actually provinces
1129 // since they are technically considered "territories" however they all
1130 // look the same on an envelope!
1131 {name
: 'Northwest Territories', abbreviation
: 'NT'},
1132 {name
: 'Nunavut', abbreviation
: 'NU'},
1133 {name
: 'Yukon', abbreviation
: 'YT'}
1137 {name
: 'Alabama', abbreviation
: 'AL'},
1138 {name
: 'Alaska', abbreviation
: 'AK'},
1139 {name
: 'Arizona', abbreviation
: 'AZ'},
1140 {name
: 'Arkansas', abbreviation
: 'AR'},
1141 {name
: 'California', abbreviation
: 'CA'},
1142 {name
: 'Colorado', abbreviation
: 'CO'},
1143 {name
: 'Connecticut', abbreviation
: 'CT'},
1144 {name
: 'Delaware', abbreviation
: 'DE'},
1145 {name
: 'District of Columbia', abbreviation
: 'DC'},
1146 {name
: 'Florida', abbreviation
: 'FL'},
1147 {name
: 'Georgia', abbreviation
: 'GA'},
1148 {name
: 'Hawaii', abbreviation
: 'HI'},
1149 {name
: 'Idaho', abbreviation
: 'ID'},
1150 {name
: 'Illinois', abbreviation
: 'IL'},
1151 {name
: 'Indiana', abbreviation
: 'IN'},
1152 {name
: 'Iowa', abbreviation
: 'IA'},
1153 {name
: 'Kansas', abbreviation
: 'KS'},
1154 {name
: 'Kentucky', abbreviation
: 'KY'},
1155 {name
: 'Louisiana', abbreviation
: 'LA'},
1156 {name
: 'Maine', abbreviation
: 'ME'},
1157 {name
: 'Maryland', abbreviation
: 'MD'},
1158 {name
: 'Massachusetts', abbreviation
: 'MA'},
1159 {name
: 'Michigan', abbreviation
: 'MI'},
1160 {name
: 'Minnesota', abbreviation
: 'MN'},
1161 {name
: 'Mississippi', abbreviation
: 'MS'},
1162 {name
: 'Missouri', abbreviation
: 'MO'},
1163 {name
: 'Montana', abbreviation
: 'MT'},
1164 {name
: 'Nebraska', abbreviation
: 'NE'},
1165 {name
: 'Nevada', abbreviation
: 'NV'},
1166 {name
: 'New Hampshire', abbreviation
: 'NH'},
1167 {name
: 'New Jersey', abbreviation
: 'NJ'},
1168 {name
: 'New Mexico', abbreviation
: 'NM'},
1169 {name
: 'New York', abbreviation
: 'NY'},
1170 {name
: 'North Carolina', abbreviation
: 'NC'},
1171 {name
: 'North Dakota', abbreviation
: 'ND'},
1172 {name
: 'Ohio', abbreviation
: 'OH'},
1173 {name
: 'Oklahoma', abbreviation
: 'OK'},
1174 {name
: 'Oregon', abbreviation
: 'OR'},
1175 {name
: 'Pennsylvania', abbreviation
: 'PA'},
1176 {name
: 'Rhode Island', abbreviation
: 'RI'},
1177 {name
: 'South Carolina', abbreviation
: 'SC'},
1178 {name
: 'South Dakota', abbreviation
: 'SD'},
1179 {name
: 'Tennessee', abbreviation
: 'TN'},
1180 {name
: 'Texas', abbreviation
: 'TX'},
1181 {name
: 'Utah', abbreviation
: 'UT'},
1182 {name
: 'Vermont', abbreviation
: 'VT'},
1183 {name
: 'Virginia', abbreviation
: 'VA'},
1184 {name
: 'Washington', abbreviation
: 'WA'},
1185 {name
: 'West Virginia', abbreviation
: 'WV'},
1186 {name
: 'Wisconsin', abbreviation
: 'WI'},
1187 {name
: 'Wyoming', abbreviation
: 'WY'}
1191 {name
: 'American Samoa', abbreviation
: 'AS'},
1192 {name
: 'Federated States of Micronesia', abbreviation
: 'FM'},
1193 {name
: 'Guam', abbreviation
: 'GU'},
1194 {name
: 'Marshall Islands', abbreviation
: 'MH'},
1195 {name
: 'Northern Mariana Islands', abbreviation
: 'MP'},
1196 {name
: 'Puerto Rico', abbreviation
: 'PR'},
1197 {name
: 'Virgin Islands, U.S.', abbreviation
: 'VI'}
1201 {name
: 'Armed Forces Europe', abbreviation
: 'AE'},
1202 {name
: 'Armed Forces Pacific', abbreviation
: 'AP'},
1203 {name
: 'Armed Forces the Americas', abbreviation
: 'AA'}
1207 {name
: 'Avenue', abbreviation
: 'Ave'},
1208 {name
: 'Boulevard', abbreviation
: 'Blvd'},
1209 {name
: 'Center', abbreviation
: 'Ctr'},
1210 {name
: 'Circle', abbreviation
: 'Cir'},
1211 {name
: 'Court', abbreviation
: 'Ct'},
1212 {name
: 'Drive', abbreviation
: 'Dr'},
1213 {name
: 'Extension', abbreviation
: 'Ext'},
1214 {name
: 'Glen', abbreviation
: 'Gln'},
1215 {name
: 'Grove', abbreviation
: 'Grv'},
1216 {name
: 'Heights', abbreviation
: 'Hts'},
1217 {name
: 'Highway', abbreviation
: 'Hwy'},
1218 {name
: 'Junction', abbreviation
: 'Jct'},
1219 {name
: 'Key', abbreviation
: 'Key'},
1220 {name
: 'Lane', abbreviation
: 'Ln'},
1221 {name
: 'Loop', abbreviation
: 'Loop'},
1222 {name
: 'Manor', abbreviation
: 'Mnr'},
1223 {name
: 'Mill', abbreviation
: 'Mill'},
1224 {name
: 'Park', abbreviation
: 'Park'},
1225 {name
: 'Parkway', abbreviation
: 'Pkwy'},
1226 {name
: 'Pass', abbreviation
: 'Pass'},
1227 {name
: 'Path', abbreviation
: 'Path'},
1228 {name
: 'Pike', abbreviation
: 'Pike'},
1229 {name
: 'Place', abbreviation
: 'Pl'},
1230 {name
: 'Plaza', abbreviation
: 'Plz'},
1231 {name
: 'Point', abbreviation
: 'Pt'},
1232 {name
: 'Ridge', abbreviation
: 'Rdg'},
1233 {name
: 'River', abbreviation
: 'Riv'},
1234 {name
: 'Road', abbreviation
: 'Rd'},
1235 {name
: 'Square', abbreviation
: 'Sq'},
1236 {name
: 'Street', abbreviation
: 'St'},
1237 {name
: 'Terrace', abbreviation
: 'Ter'},
1238 {name
: 'Trail', abbreviation
: 'Trl'},
1239 {name
: 'Turnpike', abbreviation
: 'Tpke'},
1240 {name
: 'View', abbreviation
: 'Vw'},
1241 {name
: 'Way', abbreviation
: 'Way'}
1245 {name
: 'January', short_name
: 'Jan', numeric
: '01', days
: 31},
1246 // Not messing with leap years...
1247 {name
: 'February', short_name
: 'Feb', numeric
: '02', days
: 28},
1248 {name
: 'March', short_name
: 'Mar', numeric
: '03', days
: 31},
1249 {name
: 'April', short_name
: 'Apr', numeric
: '04', days
: 30},
1250 {name
: 'May', short_name
: 'May', numeric
: '05', days
: 31},
1251 {name
: 'June', short_name
: 'Jun', numeric
: '06', days
: 30},
1252 {name
: 'July', short_name
: 'Jul', numeric
: '07', days
: 31},
1253 {name
: 'August', short_name
: 'Aug', numeric
: '08', days
: 31},
1254 {name
: 'September', short_name
: 'Sep', numeric
: '09', days
: 30},
1255 {name
: 'October', short_name
: 'Oct', numeric
: '10', days
: 31},
1256 {name
: 'November', short_name
: 'Nov', numeric
: '11', days
: 30},
1257 {name
: 'December', short_name
: 'Dec', numeric
: '12', days
: 31}
1260 // http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
1262 {name
: "American Express", short_name
: 'amex', prefix
: '34', length
: 15},
1263 {name
: "Bankcard", short_name
: 'bankcard', prefix
: '5610', length
: 16},
1264 {name
: "China UnionPay", short_name
: 'chinaunion', prefix
: '62', length
: 16},
1265 {name
: "Diners Club Carte Blanche", short_name
: 'dccarte', prefix
: '300', length
: 14},
1266 {name
: "Diners Club enRoute", short_name
: 'dcenroute', prefix
: '2014', length
: 15},
1267 {name
: "Diners Club International", short_name
: 'dcintl', prefix
: '36', length
: 14},
1268 {name
: "Diners Club United States & Canada", short_name
: 'dcusc', prefix
: '54', length
: 16},
1269 {name
: "Discover Card", short_name
: 'discover', prefix
: '6011', length
: 16},
1270 {name
: "InstaPayment", short_name
: 'instapay', prefix
: '637', length
: 16},
1271 {name
: "JCB", short_name
: 'jcb', prefix
: '3528', length
: 16},
1272 {name
: "Laser", short_name
: 'laser', prefix
: '6304', length
: 16},
1273 {name
: "Maestro", short_name
: 'maestro', prefix
: '5018', length
: 16},
1274 {name
: "Mastercard", short_name
: 'mc', prefix
: '51', length
: 16},
1275 {name
: "Solo", short_name
: 'solo', prefix
: '6334', length
: 16},
1276 {name
: "Switch", short_name
: 'switch', prefix
: '4903', length
: 16},
1277 {name
: "Visa", short_name
: 'visa', prefix
: '4', length
: 16},
1278 {name
: "Visa Electron", short_name
: 'electron', prefix
: '4026', length
: 16}
1281 //return all world currency by ISO 4217
1283 {'code' : 'AED', 'name' : 'United Arab Emirates Dirham'},
1284 {'code' : 'AFN', 'name' : 'Afghanistan Afghani'},
1285 {'code' : 'ALL', 'name' : 'Albania Lek'},
1286 {'code' : 'AMD', 'name' : 'Armenia Dram'},
1287 {'code' : 'ANG', 'name' : 'Netherlands Antilles Guilder'},
1288 {'code' : 'AOA', 'name' : 'Angola Kwanza'},
1289 {'code' : 'ARS', 'name' : 'Argentina Peso'},
1290 {'code' : 'AUD', 'name' : 'Australia Dollar'},
1291 {'code' : 'AWG', 'name' : 'Aruba Guilder'},
1292 {'code' : 'AZN', 'name' : 'Azerbaijan New Manat'},
1293 {'code' : 'BAM', 'name' : 'Bosnia and Herzegovina Convertible Marka'},
1294 {'code' : 'BBD', 'name' : 'Barbados Dollar'},
1295 {'code' : 'BDT', 'name' : 'Bangladesh Taka'},
1296 {'code' : 'BGN', 'name' : 'Bulgaria Lev'},
1297 {'code' : 'BHD', 'name' : 'Bahrain Dinar'},
1298 {'code' : 'BIF', 'name' : 'Burundi Franc'},
1299 {'code' : 'BMD', 'name' : 'Bermuda Dollar'},
1300 {'code' : 'BND', 'name' : 'Brunei Darussalam Dollar'},
1301 {'code' : 'BOB', 'name' : 'Bolivia Boliviano'},
1302 {'code' : 'BRL', 'name' : 'Brazil Real'},
1303 {'code' : 'BSD', 'name' : 'Bahamas Dollar'},
1304 {'code' : 'BTN', 'name' : 'Bhutan Ngultrum'},
1305 {'code' : 'BWP', 'name' : 'Botswana Pula'},
1306 {'code' : 'BYR', 'name' : 'Belarus Ruble'},
1307 {'code' : 'BZD', 'name' : 'Belize Dollar'},
1308 {'code' : 'CAD', 'name' : 'Canada Dollar'},
1309 {'code' : 'CDF', 'name' : 'Congo/Kinshasa Franc'},
1310 {'code' : 'CHF', 'name' : 'Switzerland Franc'},
1311 {'code' : 'CLP', 'name' : 'Chile Peso'},
1312 {'code' : 'CNY', 'name' : 'China Yuan Renminbi'},
1313 {'code' : 'COP', 'name' : 'Colombia Peso'},
1314 {'code' : 'CRC', 'name' : 'Costa Rica Colon'},
1315 {'code' : 'CUC', 'name' : 'Cuba Convertible Peso'},
1316 {'code' : 'CUP', 'name' : 'Cuba Peso'},
1317 {'code' : 'CVE', 'name' : 'Cape Verde Escudo'},
1318 {'code' : 'CZK', 'name' : 'Czech Republic Koruna'},
1319 {'code' : 'DJF', 'name' : 'Djibouti Franc'},
1320 {'code' : 'DKK', 'name' : 'Denmark Krone'},
1321 {'code' : 'DOP', 'name' : 'Dominican Republic Peso'},
1322 {'code' : 'DZD', 'name' : 'Algeria Dinar'},
1323 {'code' : 'EGP', 'name' : 'Egypt Pound'},
1324 {'code' : 'ERN', 'name' : 'Eritrea Nakfa'},
1325 {'code' : 'ETB', 'name' : 'Ethiopia Birr'},
1326 {'code' : 'EUR', 'name' : 'Euro Member Countries'},
1327 {'code' : 'FJD', 'name' : 'Fiji Dollar'},
1328 {'code' : 'FKP', 'name' : 'Falkland Islands (Malvinas) Pound'},
1329 {'code' : 'GBP', 'name' : 'United Kingdom Pound'},
1330 {'code' : 'GEL', 'name' : 'Georgia Lari'},
1331 {'code' : 'GGP', 'name' : 'Guernsey Pound'},
1332 {'code' : 'GHS', 'name' : 'Ghana Cedi'},
1333 {'code' : 'GIP', 'name' : 'Gibraltar Pound'},
1334 {'code' : 'GMD', 'name' : 'Gambia Dalasi'},
1335 {'code' : 'GNF', 'name' : 'Guinea Franc'},
1336 {'code' : 'GTQ', 'name' : 'Guatemala Quetzal'},
1337 {'code' : 'GYD', 'name' : 'Guyana Dollar'},
1338 {'code' : 'HKD', 'name' : 'Hong Kong Dollar'},
1339 {'code' : 'HNL', 'name' : 'Honduras Lempira'},
1340 {'code' : 'HRK', 'name' : 'Croatia Kuna'},
1341 {'code' : 'HTG', 'name' : 'Haiti Gourde'},
1342 {'code' : 'HUF', 'name' : 'Hungary Forint'},
1343 {'code' : 'IDR', 'name' : 'Indonesia Rupiah'},
1344 {'code' : 'ILS', 'name' : 'Israel Shekel'},
1345 {'code' : 'IMP', 'name' : 'Isle of Man Pound'},
1346 {'code' : 'INR', 'name' : 'India Rupee'},
1347 {'code' : 'IQD', 'name' : 'Iraq Dinar'},
1348 {'code' : 'IRR', 'name' : 'Iran Rial'},
1349 {'code' : 'ISK', 'name' : 'Iceland Krona'},
1350 {'code' : 'JEP', 'name' : 'Jersey Pound'},
1351 {'code' : 'JMD', 'name' : 'Jamaica Dollar'},
1352 {'code' : 'JOD', 'name' : 'Jordan Dinar'},
1353 {'code' : 'JPY', 'name' : 'Japan Yen'},
1354 {'code' : 'KES', 'name' : 'Kenya Shilling'},
1355 {'code' : 'KGS', 'name' : 'Kyrgyzstan Som'},
1356 {'code' : 'KHR', 'name' : 'Cambodia Riel'},
1357 {'code' : 'KMF', 'name' : 'Comoros Franc'},
1358 {'code' : 'KPW', 'name' : 'Korea (North) Won'},
1359 {'code' : 'KRW', 'name' : 'Korea (South) Won'},
1360 {'code' : 'KWD', 'name' : 'Kuwait Dinar'},
1361 {'code' : 'KYD', 'name' : 'Cayman Islands Dollar'},
1362 {'code' : 'KZT', 'name' : 'Kazakhstan Tenge'},
1363 {'code' : 'LAK', 'name' : 'Laos Kip'},
1364 {'code' : 'LBP', 'name' : 'Lebanon Pound'},
1365 {'code' : 'LKR', 'name' : 'Sri Lanka Rupee'},
1366 {'code' : 'LRD', 'name' : 'Liberia Dollar'},
1367 {'code' : 'LSL', 'name' : 'Lesotho Loti'},
1368 {'code' : 'LTL', 'name' : 'Lithuania Litas'},
1369 {'code' : 'LYD', 'name' : 'Libya Dinar'},
1370 {'code' : 'MAD', 'name' : 'Morocco Dirham'},
1371 {'code' : 'MDL', 'name' : 'Moldova Leu'},
1372 {'code' : 'MGA', 'name' : 'Madagascar Ariary'},
1373 {'code' : 'MKD', 'name' : 'Macedonia Denar'},
1374 {'code' : 'MMK', 'name' : 'Myanmar (Burma) Kyat'},
1375 {'code' : 'MNT', 'name' : 'Mongolia Tughrik'},
1376 {'code' : 'MOP', 'name' : 'Macau Pataca'},
1377 {'code' : 'MRO', 'name' : 'Mauritania Ouguiya'},
1378 {'code' : 'MUR', 'name' : 'Mauritius Rupee'},
1379 {'code' : 'MVR', 'name' : 'Maldives (Maldive Islands) Rufiyaa'},
1380 {'code' : 'MWK', 'name' : 'Malawi Kwacha'},
1381 {'code' : 'MXN', 'name' : 'Mexico Peso'},
1382 {'code' : 'MYR', 'name' : 'Malaysia Ringgit'},
1383 {'code' : 'MZN', 'name' : 'Mozambique Metical'},
1384 {'code' : 'NAD', 'name' : 'Namibia Dollar'},
1385 {'code' : 'NGN', 'name' : 'Nigeria Naira'},
1386 {'code' : 'NIO', 'name' : 'Nicaragua Cordoba'},
1387 {'code' : 'NOK', 'name' : 'Norway Krone'},
1388 {'code' : 'NPR', 'name' : 'Nepal Rupee'},
1389 {'code' : 'NZD', 'name' : 'New Zealand Dollar'},
1390 {'code' : 'OMR', 'name' : 'Oman Rial'},
1391 {'code' : 'PAB', 'name' : 'Panama Balboa'},
1392 {'code' : 'PEN', 'name' : 'Peru Nuevo Sol'},
1393 {'code' : 'PGK', 'name' : 'Papua New Guinea Kina'},
1394 {'code' : 'PHP', 'name' : 'Philippines Peso'},
1395 {'code' : 'PKR', 'name' : 'Pakistan Rupee'},
1396 {'code' : 'PLN', 'name' : 'Poland Zloty'},
1397 {'code' : 'PYG', 'name' : 'Paraguay Guarani'},
1398 {'code' : 'QAR', 'name' : 'Qatar Riyal'},
1399 {'code' : 'RON', 'name' : 'Romania New Leu'},
1400 {'code' : 'RSD', 'name' : 'Serbia Dinar'},
1401 {'code' : 'RUB', 'name' : 'Russia Ruble'},
1402 {'code' : 'RWF', 'name' : 'Rwanda Franc'},
1403 {'code' : 'SAR', 'name' : 'Saudi Arabia Riyal'},
1404 {'code' : 'SBD', 'name' : 'Solomon Islands Dollar'},
1405 {'code' : 'SCR', 'name' : 'Seychelles Rupee'},
1406 {'code' : 'SDG', 'name' : 'Sudan Pound'},
1407 {'code' : 'SEK', 'name' : 'Sweden Krona'},
1408 {'code' : 'SGD', 'name' : 'Singapore Dollar'},
1409 {'code' : 'SHP', 'name' : 'Saint Helena Pound'},
1410 {'code' : 'SLL', 'name' : 'Sierra Leone Leone'},
1411 {'code' : 'SOS', 'name' : 'Somalia Shilling'},
1412 {'code' : 'SPL', 'name' : 'Seborga Luigino'},
1413 {'code' : 'SRD', 'name' : 'Suriname Dollar'},
1414 {'code' : 'STD', 'name' : 'São Tomé and PrÃncipe Dobra'},
1415 {'code' : 'SVC', 'name' : 'El Salvador Colon'},
1416 {'code' : 'SYP', 'name' : 'Syria Pound'},
1417 {'code' : 'SZL', 'name' : 'Swaziland Lilangeni'},
1418 {'code' : 'THB', 'name' : 'Thailand Baht'},
1419 {'code' : 'TJS', 'name' : 'Tajikistan Somoni'},
1420 {'code' : 'TMT', 'name' : 'Turkmenistan Manat'},
1421 {'code' : 'TND', 'name' : 'Tunisia Dinar'},
1422 {'code' : 'TOP', 'name' : 'Tonga Pa\'anga'},
1423 {'code' : 'TRY', 'name' : 'Turkey Lira'},
1424 {'code' : 'TTD', 'name' : 'Trinidad and Tobago Dollar'},
1425 {'code' : 'TVD', 'name' : 'Tuvalu Dollar'},
1426 {'code' : 'TWD', 'name' : 'Taiwan New Dollar'},
1427 {'code' : 'TZS', 'name' : 'Tanzania Shilling'},
1428 {'code' : 'UAH', 'name' : 'Ukraine Hryvnia'},
1429 {'code' : 'UGX', 'name' : 'Uganda Shilling'},
1430 {'code' : 'USD', 'name' : 'United States Dollar'},
1431 {'code' : 'UYU', 'name' : 'Uruguay Peso'},
1432 {'code' : 'UZS', 'name' : 'Uzbekistan Som'},
1433 {'code' : 'VEF', 'name' : 'Venezuela Bolivar'},
1434 {'code' : 'VND', 'name' : 'Viet Nam Dong'},
1435 {'code' : 'VUV', 'name' : 'Vanuatu Vatu'},
1436 {'code' : 'WST', 'name' : 'Samoa Tala'},
1437 {'code' : 'XAF', 'name' : 'Communauté Financière Africaine (BEAC) CFA Franc BEAC'},
1438 {'code' : 'XCD', 'name' : 'East Caribbean Dollar'},
1439 {'code' : 'XDR', 'name' : 'International Monetary Fund (IMF) Special Drawing Rights'},
1440 {'code' : 'XOF', 'name' : 'Communauté Financière Africaine (BCEAO) Franc'},
1441 {'code' : 'XPF', 'name' : 'Comptoirs Français du Pacifique (CFP) Franc'},
1442 {'code' : 'YER', 'name' : 'Yemen Rial'},
1443 {'code' : 'ZAR', 'name' : 'South Africa Rand'},
1444 {'code' : 'ZMW', 'name' : 'Zambia Kwacha'},
1445 {'code' : 'ZWD', 'name' : 'Zimbabwe Dollar'}
1449 function copyObject(source
, target
) {
1452 target
= target
|| (Array
.isArray(source
) ? [] : {});
1454 for (key
in source
) {
1455 if (source
.hasOwnProperty(key
)) {
1456 target
[key
] = source
[key
] || target
[key
];
1463 /** Get the data based on key**/
1464 Chance
.prototype.get = function (name
) {
1465 return copyObject(data
[name
]);
1469 Chance
.prototype.mac_address = function(options
){
1470 // typically mac addresses are separated by ":"
1471 // however they can also be separated by "-"
1472 // the network variant uses a dot every fourth byte
1474 options
= initOptions(options
);
1475 if(!options
.separator
) {
1476 options
.separator
= options
.networkVersion
? "." : ":";
1479 var mac_pool
="ABCDEF1234567890",
1481 if(!options
.networkVersion
) {
1482 mac
= this.n(this.string
, 6, { pool
: mac_pool
, length
:2 }).join(options
.separator
);
1484 mac
= this.n(this.string
, 3, { pool
: mac_pool
, length
:4 }).join(options
.separator
);
1490 Chance
.prototype.normal = function (options
) {
1491 options
= initOptions(options
, {mean
: 0, dev
: 1});
1493 // The Marsaglia Polar method
1495 mean
= options
.mean
,
1499 // U and V are from the uniform distribution on (-1, 1)
1500 u
= this.random() * 2 - 1;
1501 v
= this.random() * 2 - 1;
1506 // Compute the standard normal variate
1507 norm
= u
* Math
.sqrt(-2 * Math
.log(s
) / s
);
1510 return dev
* norm
+ mean
;
1513 Chance
.prototype.radio = function (options
) {
1514 // Initial Letter (Typically Designated by Side of Mississippi River)
1515 options
= initOptions(options
, {side
: "?"});
1517 switch (options
.side
.toLowerCase()) {
1527 fl
= this.character({pool
: "KW"});
1531 return fl
+ this.character({alpha
: true, casing
: "upper"}) +
1532 this.character({alpha
: true, casing
: "upper"}) +
1533 this.character({alpha
: true, casing
: "upper"});
1536 // Set the data as key and data or the data map
1537 Chance
.prototype.set = function (name
, values
) {
1538 if (typeof name
=== "string") {
1539 data
[name
] = values
;
1541 data
= copyObject(name
, data
);
1545 Chance
.prototype.tv = function (options
) {
1546 return this.radio(options
);
1549 // -- End Miscellaneous --
1551 Chance
.prototype.mersenne_twister = function (seed
) {
1552 return new MersenneTwister(seed
);
1555 // Mersenne Twister from https://gist.github.com/banksean/300494
1556 var MersenneTwister = function (seed
) {
1557 if (seed
=== undefined) {
1558 seed
= new Date().getTime();
1560 /* Period parameters */
1563 this.MATRIX_A
= 0x9908b0df; /* constant vector a */
1564 this.UPPER_MASK
= 0x80000000; /* most significant w-r bits */
1565 this.LOWER_MASK
= 0x7fffffff; /* least significant r bits */
1567 this.mt
= new Array(this.N
); /* the array for the state vector */
1568 this.mti
= this.N
+ 1; /* mti==N + 1 means mt[N] is not initialized */
1570 this.init_genrand(seed
);
1573 /* initializes mt[N] with a seed */
1574 MersenneTwister
.prototype.init_genrand = function (s
) {
1575 this.mt
[0] = s
>>> 0;
1576 for (this.mti
= 1; this.mti
< this.N
; this.mti
++) {
1577 s
= this.mt
[this.mti
- 1] ^ (this.mt
[this.mti
- 1] >>> 30);
1578 this.mt
[this.mti
] = (((((s
& 0xffff0000) >>> 16) * 1812433253) << 16) + (s
& 0x0000ffff) * 1812433253) + this.mti
;
1579 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
1580 /* In the previous versions, MSBs of the seed affect */
1581 /* only MSBs of the array mt[]. */
1582 /* 2002/01/09 modified by Makoto Matsumoto */
1583 this.mt
[this.mti
] >>>= 0;
1584 /* for >32 bit machines */
1588 /* initialize by an array with array-length */
1589 /* init_key is the array for initializing keys */
1590 /* key_length is its length */
1591 /* slight change for C++, 2004/2/26 */
1592 MersenneTwister.prototype.init_by_array = function (init_key, key_length) {
1593 var i = 1, j = 0, k, s;
1594 this.init_genrand(19650218);
1595 k = (this.N > key_length ? this.N : key_length);
1597 s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30);
1598 this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525))) + init_key[j] + j; /* non linear */
1599 this.mt
[i
] >>>= 0; /* for WORDSIZE > 32 machines */
1602 if (i
>= this.N
) { this.mt
[0] = this.mt
[this.N
- 1]; i
= 1; }
1603 if (j
>= key_length
) { j
= 0; }
1605 for (k
= this.N
- 1; k
; k
--) {
1606 s
= this.mt
[i
- 1] ^ (this.mt
[i
- 1] >>> 30);
1607 this.mt
[i
] = (this.mt
[i
] ^ (((((s
& 0xffff0000) >>> 16) * 1566083941) << 16) + (s
& 0x0000ffff) * 1566083941)) - i
; /* non linear */
1608 this.mt
[i
] >>>= 0; /* for WORDSIZE > 32 machines */
1610 if (i
>= this.N
) { this.mt
[0] = this.mt
[this.N
- 1]; i
= 1; }
1613 this.mt
[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
1616 /* generates a random number on [0,0xffffffff]-interval */
1617 MersenneTwister
.prototype.genrand_int32 = function () {
1619 var mag01
= new Array(0x0, this.MATRIX_A
);
1620 /* mag01[x] = x * MATRIX_A for x=0,1 */
1622 if (this.mti
>= this.N
) { /* generate N words at one time */
1625 if (this.mti
=== this.N
+ 1) { /* if init_genrand() has not been called, */
1626 this.init_genrand(5489); /* a default initial seed is used */
1628 for (kk
= 0; kk
< this.N
- this.M
; kk
++) {
1629 y
= (this.mt
[kk
]&this.UPPER_MASK
)|(this.mt
[kk
+ 1]&this.LOWER_MASK
);
1630 this.mt
[kk
] = this.mt
[kk
+ this.M
] ^ (y
>>> 1) ^ mag01
[y
& 0x1];
1632 for (;kk
< this.N
- 1; kk
++) {
1633 y
= (this.mt
[kk
]&this.UPPER_MASK
)|(this.mt
[kk
+ 1]&this.LOWER_MASK
);
1634 this.mt
[kk
] = this.mt
[kk
+ (this.M
- this.N
)] ^ (y
>>> 1) ^ mag01
[y
& 0x1];
1636 y
= (this.mt
[this.N
- 1]&this.UPPER_MASK
)|(this.mt
[0]&this.LOWER_MASK
);
1637 this.mt
[this.N
- 1] = this.mt
[this.M
- 1] ^ (y
>>> 1) ^ mag01
[y
& 0x1];
1642 y
= this.mt
[this.mti
++];
1646 y
^= (y
<< 7) & 0x9d2c5680;
1647 y
^= (y
<< 15) & 0xefc60000;
1653 /* generates a random number on [0,0x7fffffff]-interval */
1654 MersenneTwister
.prototype.genrand_int31 = function () {
1655 return (this.genrand_int32() >>> 1);
1658 /* generates a random number on [0,1]-real-interval */
1659 MersenneTwister
.prototype.genrand_real1 = function () {
1660 return this.genrand_int32() * (1.0 / 4294967295.0);
1661 /* divided by 2^32-1 */
1664 /* generates a random number on [0,1)-real-interval */
1665 MersenneTwister
.prototype.random = function () {
1666 return this.genrand_int32() * (1.0 / 4294967296.0);
1667 /* divided by 2^32 */
1670 /* generates a random number on (0,1)-real-interval */
1671 MersenneTwister
.prototype.genrand_real3 = function () {
1672 return (this.genrand_int32() + 0.5) * (1.0 / 4294967296.0);
1673 /* divided by 2^32 */
1676 /* generates a random number on [0,1) with 53-bit resolution*/
1677 MersenneTwister
.prototype.genrand_res53 = function () {
1678 var a
= this.genrand_int32()>>>5, b
= this.genrand_int32()>>>6;
1679 return (a
* 67108864.0 + b
) * (1.0 / 9007199254740992.0);
1684 if (typeof exports
!== 'undefined') {
1685 if (typeof module
!== 'undefined' && module
.exports
) {
1686 exports
= module
.exports
= Chance
;
1688 exports
.Chance
= Chance
;
1691 // Register as an anonymous AMD module
1692 if (typeof define
=== 'function' && define
.amd
) {
1693 define([], function () {
1698 // If there is a window object, that at least has a document property,
1699 // instantiate and define chance on the window
1700 if (typeof window
=== "object" && typeof window
.document
=== "object") {
1701 window
.Chance
= Chance
;
1702 window
.chance
= new Chance();