UNPKG

79.7 kBJavaScriptView Raw
1// Chance.js 0.6.2
2// http://chancejs.com
3// (c) 2013 Victor Quinn
4// Chance may be freely distributed or modified under the MIT license.
5
6(function () {
7
8 // Constants
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";
15
16 // Cached array helpers
17 var slice = Array.prototype.slice;
18
19 // Constructor
20 function Chance (seed) {
21 if (!(this instanceof Chance)) {
22 return new Chance(seed);
23 }
24
25 if (seed !== undefined) {
26 // If we were passed a generator rather than a seed, use it.
27 if (typeof seed === 'function') {
28 this.random = seed;
29 } else {
30 this.seed = seed;
31 }
32 }
33
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);
39 };
40 }
41
42 return this;
43 }
44
45 Chance.prototype.VERSION = "0.6.2";
46
47 // Random helper functions
48 function initOptions(options, defaults) {
49 options || (options = {});
50
51 if (defaults) {
52 for (var i in defaults) {
53 if (typeof options[i] === 'undefined') {
54 options[i] = defaults[i];
55 }
56 }
57 }
58
59 return options;
60 }
61
62 function testRange(test, errorMessage) {
63 if (test) {
64 throw new RangeError(errorMessage);
65 }
66 }
67
68 // -- Basics --
69
70 Chance.prototype.bool = function (options) {
71
72 // likelihood of success (true)
73 options = initOptions(options, {likelihood : 50});
74
75 testRange(
76 options.likelihood < 0 || options.likelihood > 100,
77 "Chance: Likelihood accepts values from 0 to 100."
78 );
79
80 return this.random() * 100 < options.likelihood;
81 };
82
83 Chance.prototype.character = function (options) {
84 options = initOptions(options);
85
86 var symbols = "!@#$%^&*()[]",
87 letters, pool;
88
89 testRange(
90 options.alpha && options.symbols,
91 "Chance: Cannot specify both alpha and symbols."
92 );
93
94
95 if (options.casing === 'lower') {
96 letters = CHARS_LOWER;
97 } else if (options.casing === 'upper') {
98 letters = CHARS_UPPER;
99 } else {
100 letters = CHARS_LOWER + CHARS_UPPER;
101 }
102
103 if (options.pool) {
104 pool = options.pool;
105 } else if (options.alpha) {
106 pool = letters;
107 } else if (options.symbols) {
108 pool = symbols;
109 } else {
110 pool = letters + NUMBERS + symbols;
111 }
112
113 return pool.charAt(this.natural({max: (pool.length - 1)}));
114 };
115
116 // Note, wanted to use "float" or "double" but those are both JS reserved words.
117
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
121 // needed
122 Chance.prototype.floating = function (options) {
123 var num;
124
125 options = initOptions(options, {fixed : 4});
126 var fixed = Math.pow(10, options.fixed);
127
128 testRange(
129 options.fixed && options.precision,
130 "Chance: Cannot specify both fixed and precision."
131 );
132
133 var max = MAX_INT / fixed;
134 var min = -max;
135
136 testRange(
137 options.min && options.fixed && options.min < min,
138 "Chance: Min specified is out of range with fixed. Min should be, at least, " + min
139 );
140 testRange(
141 options.max && options.fixed && options.max > max,
142 "Chance: Max specified is out of range with fixed. Max should be, at most, " + max
143 );
144
145 options = initOptions(options, {min : min, max : max});
146
147 // Todo - Make this work!
148 // options.precision = (typeof options.precision !== "undefined") ? options.precision : false;
149
150 num = this.integer({min: options.min * fixed, max: options.max * fixed});
151 var num_fixed = (num / fixed).toFixed(options.fixed);
152
153 return parseFloat(num_fixed);
154 };
155
156 // NOTE the max and min are INCLUDED in the range. So:
157 //
158 // chance.natural({min: 1, max: 3});
159 //
160 // would return either 1, 2, or 3.
161
162 Chance.prototype.integer = function (options) {
163
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});
167
168 testRange(options.min > options.max, "Chance: Min cannot be greater than Max.");
169
170 return Math.floor(this.random() * (options.max - options.min + 1) + options.min);
171 };
172
173 Chance.prototype.natural = function (options) {
174 options = initOptions(options, {min: 0, max: MAX_INT});
175 return this.integer(options);
176 };
177
178 Chance.prototype.string = function (options) {
179 options = initOptions(options);
180
181 var length = options.length || this.natural({min: 5, max: 20}),
182 pool = options.pool,
183 text = this.n(this.character, length, {pool: pool});
184
185 return text.join("");
186 };
187
188 // -- End Basics --
189
190 // -- Helpers --
191
192 Chance.prototype.capitalize = function (word) {
193 return word.charAt(0).toUpperCase() + word.substr(1);
194 };
195
196 Chance.prototype.mixin = function (obj) {
197 for (var func_name in obj) {
198 Chance.prototype[func_name] = obj[func_name];
199 }
200 return this;
201 };
202
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;
211 }
212 });
213
214 var arr = [], count = 0, result, MAX_DUPLICATES = num * 50, params = slice.call(arguments, 2);
215
216 while (arr.length < num) {
217 result = fn.apply(this, params);
218 if (!options.comparator(arr, result)) {
219 arr.push(result);
220 // reset count when unique found
221 count = 0;
222 }
223
224 if (++count > MAX_DUPLICATES) {
225 throw new RangeError("Chance: num is likely too large for sample set");
226 }
227 }
228 return arr;
229 };
230
231 /**
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
237 */
238 Chance.prototype.n = function(fn, n, options) {
239 var i = n || 1, arr = [], params = slice.call(arguments, 2);
240
241 for (null; i--; null) {
242 arr.push(fn.apply(this, params));
243 }
244
245 return arr;
246 };
247
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
251 pad = pad || '0';
252 // Convert number to a string
253 number = number + '';
254 return number.length >= width ? number : new Array(width - number.length + 1).join(pad) + number;
255 };
256
257 Chance.prototype.pick = function (arr, count) {
258 if (!count || count === 1) {
259 return arr[this.natural({max: arr.length - 1})];
260 } else {
261 return this.shuffle(arr).slice(0, count);
262 }
263 };
264
265 Chance.prototype.shuffle = function (arr) {
266 var old_array = arr.slice(0),
267 new_array = [],
268 j = 0,
269 length = Number(old_array.length);
270
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);
278 }
279
280 return new_array;
281 };
282
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");
287 }
288
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;
294 }, weights[0]);
295
296 var scaling_factor = 1 / min;
297
298 weights = weights.map(function(weight) {
299 return weight * scaling_factor;
300 });
301 }
302
303 var sum = weights.reduce(function(total, weight) {
304 return total + weight;
305 }, 0);
306
307 // get an index
308 var selected = this.natural({ min: 1, max: sum });
309
310 var total = 0;
311 var chosen;
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) {
315 chosen = arr[index];
316 return true;
317 }
318 total += weight;
319 return false;
320 });
321
322 return chosen;
323 };
324
325 // -- End Helpers --
326
327 // -- Text --
328
329 Chance.prototype.paragraph = function (options) {
330 options = initOptions(options);
331
332 var sentences = options.sentences || this.natural({min: 3, max: 7}),
333 sentence_array = this.n(this.sentence, sentences);
334
335 return sentence_array.join(' ');
336 };
337
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);
342
343 var words = options.words || this.natural({min: 12, max: 18}),
344 text, word_array = this.n(this.word, words);
345
346 text = word_array.join(' ');
347
348 // Capitalize first letter of sentence, add period at end
349 text = this.capitalize(text) + '.';
350
351 return text;
352 };
353
354 Chance.prototype.syllable = function (options) {
355 options = initOptions(options);
356
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
361 text = '',
362 chr;
363
364 // I'm sure there's a more elegant way to do this, but this works
365 // decently well.
366 for (var i = 0; i < length; i++) {
367 if (i === 0) {
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});
373 } else {
374 // Last character was a consonant, now we want a vowel
375 chr = this.character({pool: vowels});
376 }
377
378 text += chr;
379 }
380
381 return text;
382 };
383
384 Chance.prototype.word = function (options) {
385 options = initOptions(options);
386
387 testRange(
388 options.syllables && options.length,
389 "Chance: Cannot specify both syllables AND length."
390 );
391
392 var syllables = options.syllables || this.natural({min: 1, max: 3}),
393 text = '';
394
395 if (options.length) {
396 // Either bound word by length
397 do {
398 text += this.syllable();
399 } while (text.length < options.length);
400 text = text.substring(0, options.length);
401 } else {
402 // Or by number of syllables
403 for (var i = 0; i < syllables; i++) {
404 text += this.syllable();
405 }
406 }
407 return text;
408 };
409
410 // -- End Text --
411
412 // -- Person --
413
414 Chance.prototype.age = function (options) {
415 options = initOptions(options);
416 var ageRange;
417
418 switch (options.type) {
419 case 'child':
420 ageRange = {min: 1, max: 12};
421 break;
422 case 'teen':
423 ageRange = {min: 13, max: 19};
424 break;
425 case 'adult':
426 ageRange = {min: 18, max: 65};
427 break;
428 case 'senior':
429 ageRange = {min: 65, max: 100};
430 break;
431 case 'all':
432 ageRange = {min: 1, max: 100};
433 break;
434 default:
435 ageRange = {min: 18, max: 65};
436 break;
437 }
438
439 return this.natural(ageRange);
440 };
441
442 Chance.prototype.birthday = function (options) {
443 options = initOptions(options, {
444 year: (new Date().getFullYear() - this.age(options))
445 });
446
447 return this.date(options);
448 };
449
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;
454 d1 = 11 - (d1 % 11);
455 if (d1>=10) {
456 d1 = 0;
457 }
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;
459 d2 = 11 - (d2 % 11);
460 if (d2>=10) {
461 d2 = 0;
462 }
463 return ''+n[0]+n[1]+n[2]+'.'+n[3]+n[4]+n[5]+'.'+n[6]+n[7]+n[8]+'-'+d1+d2;
464 };
465
466 Chance.prototype.first = function (options) {
467 options = initOptions(options, {gender: this.gender()});
468 return this.pick(this.get("firstNames")[options.gender.toLowerCase()]);
469 };
470
471 Chance.prototype.gender = function () {
472 return this.pick(['Male', 'Female']);
473 };
474
475 Chance.prototype.last = function () {
476 return this.pick(this.get("lastNames"));
477 };
478
479 Chance.prototype.name = function (options) {
480 options = initOptions(options);
481
482 var first = this.first(options),
483 last = this.last(),
484 name;
485
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;
490 } else {
491 name = first + ' ' + last;
492 }
493
494 if (options.prefix) {
495 name = this.prefix(options) + ' ' + name;
496 }
497
498 return name;
499 };
500
501 // Return the list of available name prefixes based on supplied gender.
502 Chance.prototype.name_prefixes = function (gender) {
503 gender = gender || "all";
504
505 var prefixes = [
506 { name: 'Doctor', abbreviation: 'Dr.' }
507 ];
508
509 if (gender === "male" || gender === "all") {
510 prefixes.push({ name: 'Mister', abbreviation: 'Mr.' });
511 }
512
513 if (gender === "female" || gender === "all") {
514 prefixes.push({ name: 'Miss', abbreviation: 'Miss' });
515 prefixes.push({ name: 'Misses', abbreviation: 'Mrs.' });
516 }
517
518 return prefixes;
519 };
520
521 // Alias for name_prefix
522 Chance.prototype.prefix = function (options) {
523 return this.name_prefix(options);
524 };
525
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;
531 };
532
533 Chance.prototype.ssn = function (options) {
534 options = initOptions(options, {ssnFour: false, dashes: true});
535 var ssn_pool = "1234567890",
536 ssn,
537 dash = options.dashes ? '-' : '';
538
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});
543 } else {
544 ssn = this.string({pool: ssn_pool, length: 4});
545 }
546 return ssn;
547 };
548
549 // -- End Person --
550
551 // -- Web --
552 // Android GCM Registration ID
553 Chance.prototype.android_id = function (options) {
554 return "APA91" + this.string({ pool: "0123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_", length: 178 });
555 };
556
557 // Apple Push Token
558 Chance.prototype.apple_token = function (options) {
559 return this.string({ pool: "abcdef1234567890", length: 64 });
560 };
561
562 Chance.prototype.color = function (options) {
563 function gray(value, delimiter) {
564 return [value, value, value].join(delimiter || '');
565 }
566
567 options = initOptions(options, {format: this.pick(['hex', 'shorthex', 'rgb']), grayscale: false});
568 var isGrayscale = options.grayscale;
569
570 if (options.format === 'hex') {
571 return '#' + (isGrayscale ? gray(this.hash({length: 2})) : this.hash({length: 6}));
572 }
573
574 if (options.format === 'shorthex') {
575 return '#' + (isGrayscale ? gray(this.hash({length: 1})) : this.hash({length: 3}));
576 }
577
578 if (options.format === 'rgb') {
579 if (isGrayscale) {
580 return 'rgb(' + gray(this.natural({max: 255}), ',') + ')';
581 } else {
582 return 'rgb(' + this.natural({max: 255}) + ',' + this.natural({max: 255}) + ',' + this.natural({max: 255}) + ')';
583 }
584 }
585
586 throw new Error('Invalid format provided. Please provide one of "hex", "shorthex", or "rgb"');
587 };
588
589 Chance.prototype.domain = function (options) {
590 options = initOptions(options);
591 return this.word() + '.' + (options.tld || this.tld());
592 };
593
594 Chance.prototype.email = function (options) {
595 options = initOptions(options);
596 return this.word({length: options.length}) + '@' + (options.domain || this.domain());
597 };
598
599 Chance.prototype.fbid = function () {
600 return parseInt('10000' + this.natural({max: 100000000000}), 10);
601 };
602
603 Chance.prototype.google_analytics = function () {
604 var account = this.pad(this.natural({max: 999999}), 6);
605 var property = this.pad(this.natural({max: 99}), 2);
606
607 return 'UA-' + account + '-' + property;
608 };
609
610 Chance.prototype.hashtag = function () {
611 return '#' + this.word();
612 };
613
614 Chance.prototype.ip = function () {
615 // Todo: This could return some reserved IPs. See http://vq.io/137dgYy
616 // this should probably be updated to account for that rare as it may be
617 return this.natural({max: 255}) + '.' +
618 this.natural({max: 255}) + '.' +
619 this.natural({max: 255}) + '.' +
620 this.natural({max: 255});
621 };
622
623 Chance.prototype.ipv6 = function () {
624 var ip_addr = this.n(this.hash, 8, {length: 4});
625
626 return ip_addr.join(":");
627 };
628
629 Chance.prototype.klout = function () {
630 return this.natural({min: 1, max: 99});
631 };
632
633 Chance.prototype.tlds = function () {
634 return ['com', 'org', 'edu', 'gov', 'co.uk', 'net', 'io'];
635 };
636
637 Chance.prototype.tld = function () {
638 return this.pick(this.tlds());
639 };
640
641 Chance.prototype.twitter = function () {
642 return '@' + this.word();
643 };
644
645 // -- End Web --
646
647 // -- Location --
648
649 Chance.prototype.address = function (options) {
650 options = initOptions(options);
651 return this.natural({min: 5, max: 2000}) + ' ' + this.street(options);
652 };
653
654 Chance.prototype.altitude = function (options) {
655 options = initOptions(options, {fixed : 5, max: 8848});
656 return this.floating({min: 0, max: options.max, fixed: options.fixed});
657 };
658
659 Chance.prototype.areacode = function (options) {
660 options = initOptions(options, {parens : true});
661 // Don't want area codes to start with 1, or have a 9 as the second digit
662 var areacode = this.natural({min: 2, max: 9}).toString() +
663 this.natural({min: 0, max: 8}).toString() +
664 this.natural({min: 0, max: 9}).toString();
665
666 return options.parens ? '(' + areacode + ')' : areacode;
667 };
668
669 Chance.prototype.city = function () {
670 return this.capitalize(this.word({syllables: 3}));
671 };
672
673 Chance.prototype.coordinates = function (options) {
674 options = initOptions(options);
675 return this.latitude(options) + ', ' + this.longitude(options);
676 };
677
678 Chance.prototype.depth = function (options) {
679 options = initOptions(options, {fixed: 5, min: -2550});
680 return this.floating({min: options.min, max: 0, fixed: options.fixed});
681 };
682
683 Chance.prototype.geohash = function (options) {
684 options = initOptions(options, { length: 7 });
685 return this.string({ length: options.length, pool: '0123456789bcdefghjkmnpqrstuvwxyz' });
686 };
687
688 Chance.prototype.geojson = function (options) {
689 options = initOptions(options);
690 return this.latitude(options) + ', ' + this.longitude(options) + ', ' + this.altitude(options);
691 };
692
693 Chance.prototype.latitude = function (options) {
694 options = initOptions(options, {fixed: 5, min: -90, max: 90});
695 return this.floating({min: options.min, max: options.max, fixed: options.fixed});
696 };
697
698 Chance.prototype.longitude = function (options) {
699 options = initOptions(options, {fixed: 5, min: -180, max: 180});
700 return this.floating({min: options.min, max: options.max, fixed: options.fixed});
701 };
702
703 Chance.prototype.phone = function (options) {
704 var self = this,
705 numPick,
706 ukNum = function (parts) {
707 var section = [];
708 //fills the section part of the phone number with random numbers.
709 parts.sections.forEach(function(n) {
710 section.push(self.string({ pool: '0123456789', length: n}));
711 });
712 return parts.area + section.join(' ');
713 };
714 options = initOptions(options, {
715 formatted: true,
716 country: 'us',
717 mobile: false
718 });
719 if (!options.formatted) {
720 options.parens = false;
721 }
722 switch (options.country) {
723 case 'fr':
724 if (!options.mobile) {
725 numPick = chance.pick([
726 // Valid zone and département codes.
727 '01' + this.pick(['30', '34', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '53', '55', '56', '58', '60', '64', '69', '70', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83']) + self.string({ pool: '0123456789', length: 6}),
728 '02' + this.pick(['14', '18', '22', '23', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '40', '41', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '56', '57', '61', '62', '69', '72', '76', '77', '78', '85', '90', '96', '97', '98', '99']) + self.string({ pool: '0123456789', length: 6}),
729 '03' + this.pick(['10', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '39', '44', '45', '51', '52', '54', '55', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90']) + self.string({ pool: '0123456789', length: 6}),
730 '04' + this.pick(['11', '13', '15', '20', '22', '26', '27', '30', '32', '34', '37', '42', '43', '44', '50', '56', '57', '63', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '88', '89', '90', '91', '92', '93', '94', '95', '97', '98']) + self.string({ pool: '0123456789', length: 6}),
731 '05' + this.pick(['08', '16', '17', '19', '24', '31', '32', '33', '34', '35', '40', '45', '46', '47', '49', '53', '55', '56', '57', '58', '59', '61', '62', '63', '64', '65', '67', '79', '81', '82', '86', '87', '90', '94']) + self.string({ pool: '0123456789', length: 6}),
732 '09' + self.string({ pool: '0123456789', length: 8}),
733 ]);
734 return options.formatted ? numPick.match(/../g).join(' ') : numPick;
735 } else {
736 numPick = this.pick(['06', '07']) + self.string({ pool: '0123456789', length: 8});
737 return options.formatted ? numPick.match(/../g).join(' ') : numPick;
738 }
739 case 'uk':
740 if (!options.mobile) {
741 numPick = chance.pick([
742 //valid area codes of major cities/counties followed by random numbers in required format.
743 { area: '01' + this.character({ pool: '234569' }) + '1 ', sections: [3,4] },
744 { area: '020 ' + this.character({ pool: '378' }), sections: [3,4] },
745 { area: '023 ' + this.character({ pool: '89' }), sections: [3,4] },
746 { area: '024 7', sections: [3,4] },
747 { area: '028 ' + this.pick(['25','28','37','71','82','90','92','95']), sections: [2,4] },
748 { area: '012' + this.pick(['04','08','54','76','97','98']) + ' ', sections: [5] },
749 { area: '013' + this.pick(['63','64','84','86']) + ' ', sections: [5] },
750 { area: '014' + this.pick(['04','20','60','61','80','88']) + ' ', sections: [5] },
751 { area: '015' + this.pick(['24','27','62','66']) + ' ', sections: [5] },
752 { area: '016' + this.pick(['06','29','35','47','59','95']) + ' ', sections: [5] },
753 { area: '017' + this.pick(['26','44','50','68']) + ' ', sections: [5] },
754 { area: '018' + this.pick(['27','37','84','97']) + ' ', sections: [5] },
755 { area: '019' + this.pick(['00','05','35','46','49','63','95']) + ' ', sections: [5] }
756 ]);
757 return options.formatted ? ukNum(numPick) : ukNum(numPick).replace(' ', '', 'g');
758 } else {
759 numPick = chance.pick([
760 { area: '07' + this.pick(['4','5','7','8','9']), sections: [2,6] },
761 { area: '07624 ', sections: [6] }
762 ]);
763 return options.formatted ? ukNum(numPick) : ukNum(numPick).replace(' ', '');
764 }
765 case 'us':
766 var areacode = this.areacode(options).toString();
767 var exchange = this.natural({ min: 2, max: 9 }).toString() +
768 this.natural({ min: 0, max: 9 }).toString() +
769 this.natural({ min: 0, max: 9 }).toString();
770 var subscriber = this.natural({ min: 1000, max: 9999 }).toString(); // this could be random [0-9]{4}
771 return options.formatted ? areacode + ' ' + exchange + '-' + subscriber : areacode + exchange + subscriber;
772 }
773 };
774
775 Chance.prototype.postal = function () {
776 // Postal District
777 var pd = this.character({pool: "XVTSRPNKLMHJGECBA"});
778 // Forward Sortation Area (FSA)
779 var fsa = pd + this.natural({max: 9}) + this.character({alpha: true, casing: "upper"});
780 // Local Delivery Unut (LDU)
781 var ldu = this.natural({max: 9}) + this.character({alpha: true, casing: "upper"}) + this.natural({max: 9});
782
783 return fsa + " " + ldu;
784 };
785
786 Chance.prototype.provinces = function () {
787 return this.get("provinces");
788 };
789
790 Chance.prototype.province = function (options) {
791 return (options && options.full) ?
792 this.pick(this.provinces()).name :
793 this.pick(this.provinces()).abbreviation;
794 };
795
796 Chance.prototype.state = function (options) {
797 return (options && options.full) ?
798 this.pick(this.states(options)).name :
799 this.pick(this.states(options)).abbreviation;
800 };
801
802 Chance.prototype.states = function (options) {
803 options = initOptions(options);
804
805 var states,
806 us_states_and_dc = this.get("us_states_and_dc"),
807 territories = this.get("territories"),
808 armed_forces = this.get("armed_forces");
809
810 states = us_states_and_dc;
811
812 if (options.territories) {
813 states = states.concat(territories);
814 }
815 if (options.armed_forces) {
816 states = states.concat(armed_forces);
817 }
818
819 return states;
820 };
821
822 Chance.prototype.street = function (options) {
823 options = initOptions(options);
824
825 var street = this.word({syllables: 2});
826 street = this.capitalize(street);
827 street += ' ';
828 street += options.short_suffix ?
829 this.street_suffix().abbreviation :
830 this.street_suffix().name;
831 return street;
832 };
833
834 Chance.prototype.street_suffix = function () {
835 return this.pick(this.street_suffixes());
836 };
837
838 Chance.prototype.street_suffixes = function () {
839 // These are the most common suffixes.
840 return this.get("street_suffixes");
841 };
842
843 // Note: only returning US zip codes, internationalization will be a whole
844 // other beast to tackle at some point.
845 Chance.prototype.zip = function (options) {
846 var zip = this.n(this.natural, 5, {max: 9});
847
848 if (options && options.plusfour === true) {
849 zip.push('-');
850 zip = zip.concat(this.n(this.natural, 4, {max: 9}));
851 }
852
853 return zip.join("");
854 };
855
856 // -- End Location --
857
858 // -- Time
859
860 Chance.prototype.ampm = function () {
861 return this.bool() ? 'am' : 'pm';
862 };
863
864 Chance.prototype.date = function (options) {
865 var m = this.month({raw: true}),
866 date_string;
867
868 options = initOptions(options, {
869 year: parseInt(this.year(), 10),
870 // Necessary to subtract 1 because Date() 0-indexes month but not day or year
871 // for some reason.
872 month: m.numeric - 1,
873 day: this.natural({min: 1, max: m.days}),
874 hour: this.hour(),
875 minute: this.minute(),
876 second: this.second(),
877 millisecond: this.millisecond(),
878 american: true,
879 string: false
880 });
881
882 var date = new Date(options.year, options.month, options.day, options.hour, options.minute, options.second, options.millisecond);
883
884 if (options.american) {
885 // Adding 1 to the month is necessary because Date() 0-indexes
886 // months but not day for some odd reason.
887 date_string = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
888 } else {
889 date_string = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();
890 }
891
892 return options.string ? date_string : date;
893 };
894
895 Chance.prototype.hammertime = function (options) {
896 return this.date(options).getTime();
897 };
898
899 Chance.prototype.hour = function (options) {
900 options = initOptions(options);
901 var max = options.twentyfour ? 24 : 12;
902 return this.natural({min: 1, max: max});
903 };
904
905 Chance.prototype.millisecond = function () {
906 return this.natural({max: 999});
907 };
908
909 Chance.prototype.minute = Chance.prototype.second = function () {
910 return this.natural({max: 59});
911 };
912
913 Chance.prototype.month = function (options) {
914 options = initOptions(options);
915 var month = this.pick(this.months());
916 return options.raw ? month : month.name;
917 };
918
919 Chance.prototype.months = function () {
920 return this.get("months");
921 };
922
923 Chance.prototype.second = function () {
924 return this.natural({max: 59});
925 };
926
927 Chance.prototype.timestamp = function () {
928 return this.natural({min: 1, max: parseInt(new Date().getTime() / 1000, 10)});
929 };
930
931 Chance.prototype.year = function (options) {
932 // Default to current year as min if none specified
933 options = initOptions(options, {min: new Date().getFullYear()});
934
935 // Default to one century after current year as max if none specified
936 options.max = (typeof options.max !== "undefined") ? options.max : options.min + 100;
937
938 return this.natural(options).toString();
939 };
940
941 // -- End Time
942
943 // -- Finance --
944
945 Chance.prototype.cc = function (options) {
946 options = initOptions(options);
947
948 var type, number, to_generate;
949
950 type = (options.type) ?
951 this.cc_type({ name: options.type, raw: true }) :
952 this.cc_type({ raw: true });
953
954 number = type.prefix.split("");
955 to_generate = type.length - type.prefix.length - 1;
956
957 // Generates n - 1 digits
958 number = number.concat(this.n(this.integer, to_generate, {min: 0, max: 9}));
959
960 // Generates the last digit according to Luhn algorithm
961 number.push(this.luhn_calculate(number.join("")));
962
963 return number.join("");
964 };
965
966 Chance.prototype.cc_types = function () {
967 // http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
968 return this.get("cc_types");
969 };
970
971 Chance.prototype.cc_type = function (options) {
972 options = initOptions(options);
973 var types = this.cc_types(),
974 type = null;
975
976 if (options.name) {
977 for (var i = 0; i < types.length; i++) {
978 // Accept either name or short_name to specify card type
979 if (types[i].name === options.name || types[i].short_name === options.name) {
980 type = types[i];
981 break;
982 }
983 }
984 if (type === null) {
985 throw new Error("Credit card type '" + options.name + "'' is not supported");
986 }
987 } else {
988 type = this.pick(types);
989 }
990
991 return options.raw ? type : type.name;
992 };
993
994 //return all world currency by ISO 4217
995 Chance.prototype.currency_types = function () {
996 return this.get("currency_types");
997 };
998
999 //return random world currency by ISO 4217
1000 Chance.prototype.currency = function () {
1001 return this.pick(this.currency_types());
1002 };
1003
1004 //Return random correct currency exchange pair (e.g. EUR/USD) or array of currency code
1005 Chance.prototype.currency_pair = function (returnAsString) {
1006 var currencies = this.unique(this.currency, 2, {
1007 comparator: function(arr, val) {
1008
1009 return arr.reduce(function(acc, item) {
1010 // If a match has been found, short circuit check and just return
1011 return acc || (item.code === val.code);
1012 }, false);
1013 }
1014 });
1015
1016 if (returnAsString) {
1017 return currencies[0] + '/' + currencies[1];
1018 } else {
1019 return currencies;
1020 }
1021 };
1022
1023 Chance.prototype.dollar = function (options) {
1024 // By default, a somewhat more sane max for dollar than all available numbers
1025 options = initOptions(options, {max : 10000, min : 0});
1026
1027 var dollar = this.floating({min: options.min, max: options.max, fixed: 2}).toString(),
1028 cents = dollar.split('.')[1];
1029
1030 if (cents === undefined) {
1031 dollar += '.00';
1032 } else if (cents.length < 2) {
1033 dollar = dollar + '0';
1034 }
1035
1036 if (dollar < 0) {
1037 return '-$' + dollar.replace('-', '');
1038 } else {
1039 return '$' + dollar;
1040 }
1041 };
1042
1043 Chance.prototype.exp = function (options) {
1044 options = initOptions(options);
1045 var exp = {};
1046
1047 exp.year = this.exp_year();
1048
1049 // If the year is this year, need to ensure month is greater than the
1050 // current month or this expiration will not be valid
1051 if (exp.year === (new Date().getFullYear())) {
1052 exp.month = this.exp_month({future: true});
1053 } else {
1054 exp.month = this.exp_month();
1055 }
1056
1057 return options.raw ? exp : exp.month + '/' + exp.year;
1058 };
1059
1060 Chance.prototype.exp_month = function (options) {
1061 options = initOptions(options);
1062 var month, month_int,
1063 curMonth = new Date().getMonth();
1064
1065 if (options.future) {
1066 do {
1067 month = this.month({raw: true}).numeric;
1068 month_int = parseInt(month, 10);
1069 } while (month_int < curMonth);
1070 } else {
1071 month = this.month({raw: true}).numeric;
1072 }
1073
1074 return month;
1075 };
1076
1077 Chance.prototype.exp_year = function () {
1078 return this.year({max: new Date().getFullYear() + 10});
1079 };
1080
1081 // -- End Finance
1082
1083 // -- Miscellaneous --
1084
1085 // Dice - For all the board game geeks out there, myself included ;)
1086 function diceFn (range) {
1087 return function () {
1088 return this.natural(range);
1089 };
1090 }
1091 Chance.prototype.d4 = diceFn({min: 1, max: 4});
1092 Chance.prototype.d6 = diceFn({min: 1, max: 6});
1093 Chance.prototype.d8 = diceFn({min: 1, max: 8});
1094 Chance.prototype.d10 = diceFn({min: 1, max: 10});
1095 Chance.prototype.d12 = diceFn({min: 1, max: 12});
1096 Chance.prototype.d20 = diceFn({min: 1, max: 20});
1097 Chance.prototype.d30 = diceFn({min: 1, max: 30});
1098 Chance.prototype.d100 = diceFn({min: 1, max: 100});
1099
1100 Chance.prototype.rpg = function (thrown, options) {
1101 options = initOptions(options);
1102 if (thrown === null) {
1103 throw new Error("A type of die roll must be included");
1104 } else {
1105 var bits = thrown.toLowerCase().split("d"),
1106 rolls = [];
1107
1108 if (bits.length !== 2 || !parseInt(bits[0], 10) || !parseInt(bits[1], 10)) {
1109 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");
1110 }
1111 for (var i = bits[0]; i > 0; i--) {
1112 rolls[i - 1] = this.natural({min: 1, max: bits[1]});
1113 }
1114 return (typeof options.sum !== 'undefined' && options.sum) ? rolls.reduce(function (p, c) { return p + c; }) : rolls;
1115 }
1116 };
1117
1118 // Guid
1119 Chance.prototype.guid = function (options) {
1120 options = initOptions(options, { version: 5 });
1121
1122 var guid_pool = "abcdef1234567890",
1123 variant_pool = "ab89",
1124 guid = this.string({ pool: guid_pool, length: 8 }) + '-' +
1125 this.string({ pool: guid_pool, length: 4 }) + '-' +
1126 // The Version
1127 options.version +
1128 this.string({ pool: guid_pool, length: 3 }) + '-' +
1129 // The Variant
1130 this.string({ pool: variant_pool, length: 1 }) +
1131 this.string({ pool: guid_pool, length: 3 }) + '-' +
1132 this.string({ pool: guid_pool, length: 12 });
1133 return guid;
1134 };
1135
1136 // Hash
1137 Chance.prototype.hash = function (options) {
1138 options = initOptions(options, {length : 40, casing: 'lower'});
1139 var pool = options.casing === 'upper' ? HEX_POOL.toUpperCase() : HEX_POOL;
1140 return this.string({pool: pool, length: options.length});
1141 };
1142
1143 Chance.prototype.luhn_check = function (num) {
1144 var str = num.toString();
1145 var checkDigit = +str.substring(str.length - 1);
1146 return checkDigit === this.luhn_calculate(+str.substring(0, str.length - 1));
1147 };
1148
1149 Chance.prototype.luhn_calculate = function (num) {
1150 var digits = num.toString().split("").reverse();
1151 var sum = 0;
1152 var digit;
1153
1154 for (var i = 0, l = digits.length; l > i; ++i) {
1155 digit = +digits[i];
1156 if (i % 2 === 0) {
1157 digit *= 2;
1158 if (digit > 9) {
1159 digit -= 9;
1160 }
1161 }
1162 sum += digit;
1163 }
1164 return (sum * 9) % 10;
1165 };
1166
1167
1168 var data = {
1169
1170 firstNames: {
1171 "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"],
1172 "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"]
1173 },
1174
1175 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'],
1176
1177 provinces: [
1178 {name: 'Alberta', abbreviation: 'AB'},
1179 {name: 'British Columbia', abbreviation: 'BC'},
1180 {name: 'Manitoba', abbreviation: 'MB'},
1181 {name: 'New Brunswick', abbreviation: 'NB'},
1182 {name: 'Newfoundland and Labrador', abbreviation: 'NL'},
1183 {name: 'Nova Scotia', abbreviation: 'NS'},
1184 {name: 'Ontario', abbreviation: 'ON'},
1185 {name: 'Prince Edward Island', abbreviation: 'PE'},
1186 {name: 'Quebec', abbreviation: 'QC'},
1187 {name: 'Saskatchewan', abbreviation: 'SK'},
1188
1189 // The case could be made that the following are not actually provinces
1190 // since they are technically considered "territories" however they all
1191 // look the same on an envelope!
1192 {name: 'Northwest Territories', abbreviation: 'NT'},
1193 {name: 'Nunavut', abbreviation: 'NU'},
1194 {name: 'Yukon', abbreviation: 'YT'}
1195 ],
1196
1197 us_states_and_dc: [
1198 {name: 'Alabama', abbreviation: 'AL'},
1199 {name: 'Alaska', abbreviation: 'AK'},
1200 {name: 'Arizona', abbreviation: 'AZ'},
1201 {name: 'Arkansas', abbreviation: 'AR'},
1202 {name: 'California', abbreviation: 'CA'},
1203 {name: 'Colorado', abbreviation: 'CO'},
1204 {name: 'Connecticut', abbreviation: 'CT'},
1205 {name: 'Delaware', abbreviation: 'DE'},
1206 {name: 'District of Columbia', abbreviation: 'DC'},
1207 {name: 'Florida', abbreviation: 'FL'},
1208 {name: 'Georgia', abbreviation: 'GA'},
1209 {name: 'Hawaii', abbreviation: 'HI'},
1210 {name: 'Idaho', abbreviation: 'ID'},
1211 {name: 'Illinois', abbreviation: 'IL'},
1212 {name: 'Indiana', abbreviation: 'IN'},
1213 {name: 'Iowa', abbreviation: 'IA'},
1214 {name: 'Kansas', abbreviation: 'KS'},
1215 {name: 'Kentucky', abbreviation: 'KY'},
1216 {name: 'Louisiana', abbreviation: 'LA'},
1217 {name: 'Maine', abbreviation: 'ME'},
1218 {name: 'Maryland', abbreviation: 'MD'},
1219 {name: 'Massachusetts', abbreviation: 'MA'},
1220 {name: 'Michigan', abbreviation: 'MI'},
1221 {name: 'Minnesota', abbreviation: 'MN'},
1222 {name: 'Mississippi', abbreviation: 'MS'},
1223 {name: 'Missouri', abbreviation: 'MO'},
1224 {name: 'Montana', abbreviation: 'MT'},
1225 {name: 'Nebraska', abbreviation: 'NE'},
1226 {name: 'Nevada', abbreviation: 'NV'},
1227 {name: 'New Hampshire', abbreviation: 'NH'},
1228 {name: 'New Jersey', abbreviation: 'NJ'},
1229 {name: 'New Mexico', abbreviation: 'NM'},
1230 {name: 'New York', abbreviation: 'NY'},
1231 {name: 'North Carolina', abbreviation: 'NC'},
1232 {name: 'North Dakota', abbreviation: 'ND'},
1233 {name: 'Ohio', abbreviation: 'OH'},
1234 {name: 'Oklahoma', abbreviation: 'OK'},
1235 {name: 'Oregon', abbreviation: 'OR'},
1236 {name: 'Pennsylvania', abbreviation: 'PA'},
1237 {name: 'Rhode Island', abbreviation: 'RI'},
1238 {name: 'South Carolina', abbreviation: 'SC'},
1239 {name: 'South Dakota', abbreviation: 'SD'},
1240 {name: 'Tennessee', abbreviation: 'TN'},
1241 {name: 'Texas', abbreviation: 'TX'},
1242 {name: 'Utah', abbreviation: 'UT'},
1243 {name: 'Vermont', abbreviation: 'VT'},
1244 {name: 'Virginia', abbreviation: 'VA'},
1245 {name: 'Washington', abbreviation: 'WA'},
1246 {name: 'West Virginia', abbreviation: 'WV'},
1247 {name: 'Wisconsin', abbreviation: 'WI'},
1248 {name: 'Wyoming', abbreviation: 'WY'}
1249 ],
1250
1251 territories: [
1252 {name: 'American Samoa', abbreviation: 'AS'},
1253 {name: 'Federated States of Micronesia', abbreviation: 'FM'},
1254 {name: 'Guam', abbreviation: 'GU'},
1255 {name: 'Marshall Islands', abbreviation: 'MH'},
1256 {name: 'Northern Mariana Islands', abbreviation: 'MP'},
1257 {name: 'Puerto Rico', abbreviation: 'PR'},
1258 {name: 'Virgin Islands, U.S.', abbreviation: 'VI'}
1259 ],
1260
1261 armed_forces: [
1262 {name: 'Armed Forces Europe', abbreviation: 'AE'},
1263 {name: 'Armed Forces Pacific', abbreviation: 'AP'},
1264 {name: 'Armed Forces the Americas', abbreviation: 'AA'}
1265 ],
1266
1267 street_suffixes: [
1268 {name: 'Avenue', abbreviation: 'Ave'},
1269 {name: 'Boulevard', abbreviation: 'Blvd'},
1270 {name: 'Center', abbreviation: 'Ctr'},
1271 {name: 'Circle', abbreviation: 'Cir'},
1272 {name: 'Court', abbreviation: 'Ct'},
1273 {name: 'Drive', abbreviation: 'Dr'},
1274 {name: 'Extension', abbreviation: 'Ext'},
1275 {name: 'Glen', abbreviation: 'Gln'},
1276 {name: 'Grove', abbreviation: 'Grv'},
1277 {name: 'Heights', abbreviation: 'Hts'},
1278 {name: 'Highway', abbreviation: 'Hwy'},
1279 {name: 'Junction', abbreviation: 'Jct'},
1280 {name: 'Key', abbreviation: 'Key'},
1281 {name: 'Lane', abbreviation: 'Ln'},
1282 {name: 'Loop', abbreviation: 'Loop'},
1283 {name: 'Manor', abbreviation: 'Mnr'},
1284 {name: 'Mill', abbreviation: 'Mill'},
1285 {name: 'Park', abbreviation: 'Park'},
1286 {name: 'Parkway', abbreviation: 'Pkwy'},
1287 {name: 'Pass', abbreviation: 'Pass'},
1288 {name: 'Path', abbreviation: 'Path'},
1289 {name: 'Pike', abbreviation: 'Pike'},
1290 {name: 'Place', abbreviation: 'Pl'},
1291 {name: 'Plaza', abbreviation: 'Plz'},
1292 {name: 'Point', abbreviation: 'Pt'},
1293 {name: 'Ridge', abbreviation: 'Rdg'},
1294 {name: 'River', abbreviation: 'Riv'},
1295 {name: 'Road', abbreviation: 'Rd'},
1296 {name: 'Square', abbreviation: 'Sq'},
1297 {name: 'Street', abbreviation: 'St'},
1298 {name: 'Terrace', abbreviation: 'Ter'},
1299 {name: 'Trail', abbreviation: 'Trl'},
1300 {name: 'Turnpike', abbreviation: 'Tpke'},
1301 {name: 'View', abbreviation: 'Vw'},
1302 {name: 'Way', abbreviation: 'Way'}
1303 ],
1304
1305 months: [
1306 {name: 'January', short_name: 'Jan', numeric: '01', days: 31},
1307 // Not messing with leap years...
1308 {name: 'February', short_name: 'Feb', numeric: '02', days: 28},
1309 {name: 'March', short_name: 'Mar', numeric: '03', days: 31},
1310 {name: 'April', short_name: 'Apr', numeric: '04', days: 30},
1311 {name: 'May', short_name: 'May', numeric: '05', days: 31},
1312 {name: 'June', short_name: 'Jun', numeric: '06', days: 30},
1313 {name: 'July', short_name: 'Jul', numeric: '07', days: 31},
1314 {name: 'August', short_name: 'Aug', numeric: '08', days: 31},
1315 {name: 'September', short_name: 'Sep', numeric: '09', days: 30},
1316 {name: 'October', short_name: 'Oct', numeric: '10', days: 31},
1317 {name: 'November', short_name: 'Nov', numeric: '11', days: 30},
1318 {name: 'December', short_name: 'Dec', numeric: '12', days: 31}
1319 ],
1320
1321 // http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
1322 cc_types: [
1323 {name: "American Express", short_name: 'amex', prefix: '34', length: 15},
1324 {name: "Bankcard", short_name: 'bankcard', prefix: '5610', length: 16},
1325 {name: "China UnionPay", short_name: 'chinaunion', prefix: '62', length: 16},
1326 {name: "Diners Club Carte Blanche", short_name: 'dccarte', prefix: '300', length: 14},
1327 {name: "Diners Club enRoute", short_name: 'dcenroute', prefix: '2014', length: 15},
1328 {name: "Diners Club International", short_name: 'dcintl', prefix: '36', length: 14},
1329 {name: "Diners Club United States & Canada", short_name: 'dcusc', prefix: '54', length: 16},
1330 {name: "Discover Card", short_name: 'discover', prefix: '6011', length: 16},
1331 {name: "InstaPayment", short_name: 'instapay', prefix: '637', length: 16},
1332 {name: "JCB", short_name: 'jcb', prefix: '3528', length: 16},
1333 {name: "Laser", short_name: 'laser', prefix: '6304', length: 16},
1334 {name: "Maestro", short_name: 'maestro', prefix: '5018', length: 16},
1335 {name: "Mastercard", short_name: 'mc', prefix: '51', length: 16},
1336 {name: "Solo", short_name: 'solo', prefix: '6334', length: 16},
1337 {name: "Switch", short_name: 'switch', prefix: '4903', length: 16},
1338 {name: "Visa", short_name: 'visa', prefix: '4', length: 16},
1339 {name: "Visa Electron", short_name: 'electron', prefix: '4026', length: 16}
1340 ],
1341
1342 //return all world currency by ISO 4217
1343 currency_types: [
1344 {'code' : 'AED', 'name' : 'United Arab Emirates Dirham'},
1345 {'code' : 'AFN', 'name' : 'Afghanistan Afghani'},
1346 {'code' : 'ALL', 'name' : 'Albania Lek'},
1347 {'code' : 'AMD', 'name' : 'Armenia Dram'},
1348 {'code' : 'ANG', 'name' : 'Netherlands Antilles Guilder'},
1349 {'code' : 'AOA', 'name' : 'Angola Kwanza'},
1350 {'code' : 'ARS', 'name' : 'Argentina Peso'},
1351 {'code' : 'AUD', 'name' : 'Australia Dollar'},
1352 {'code' : 'AWG', 'name' : 'Aruba Guilder'},
1353 {'code' : 'AZN', 'name' : 'Azerbaijan New Manat'},
1354 {'code' : 'BAM', 'name' : 'Bosnia and Herzegovina Convertible Marka'},
1355 {'code' : 'BBD', 'name' : 'Barbados Dollar'},
1356 {'code' : 'BDT', 'name' : 'Bangladesh Taka'},
1357 {'code' : 'BGN', 'name' : 'Bulgaria Lev'},
1358 {'code' : 'BHD', 'name' : 'Bahrain Dinar'},
1359 {'code' : 'BIF', 'name' : 'Burundi Franc'},
1360 {'code' : 'BMD', 'name' : 'Bermuda Dollar'},
1361 {'code' : 'BND', 'name' : 'Brunei Darussalam Dollar'},
1362 {'code' : 'BOB', 'name' : 'Bolivia Boliviano'},
1363 {'code' : 'BRL', 'name' : 'Brazil Real'},
1364 {'code' : 'BSD', 'name' : 'Bahamas Dollar'},
1365 {'code' : 'BTN', 'name' : 'Bhutan Ngultrum'},
1366 {'code' : 'BWP', 'name' : 'Botswana Pula'},
1367 {'code' : 'BYR', 'name' : 'Belarus Ruble'},
1368 {'code' : 'BZD', 'name' : 'Belize Dollar'},
1369 {'code' : 'CAD', 'name' : 'Canada Dollar'},
1370 {'code' : 'CDF', 'name' : 'Congo/Kinshasa Franc'},
1371 {'code' : 'CHF', 'name' : 'Switzerland Franc'},
1372 {'code' : 'CLP', 'name' : 'Chile Peso'},
1373 {'code' : 'CNY', 'name' : 'China Yuan Renminbi'},
1374 {'code' : 'COP', 'name' : 'Colombia Peso'},
1375 {'code' : 'CRC', 'name' : 'Costa Rica Colon'},
1376 {'code' : 'CUC', 'name' : 'Cuba Convertible Peso'},
1377 {'code' : 'CUP', 'name' : 'Cuba Peso'},
1378 {'code' : 'CVE', 'name' : 'Cape Verde Escudo'},
1379 {'code' : 'CZK', 'name' : 'Czech Republic Koruna'},
1380 {'code' : 'DJF', 'name' : 'Djibouti Franc'},
1381 {'code' : 'DKK', 'name' : 'Denmark Krone'},
1382 {'code' : 'DOP', 'name' : 'Dominican Republic Peso'},
1383 {'code' : 'DZD', 'name' : 'Algeria Dinar'},
1384 {'code' : 'EGP', 'name' : 'Egypt Pound'},
1385 {'code' : 'ERN', 'name' : 'Eritrea Nakfa'},
1386 {'code' : 'ETB', 'name' : 'Ethiopia Birr'},
1387 {'code' : 'EUR', 'name' : 'Euro Member Countries'},
1388 {'code' : 'FJD', 'name' : 'Fiji Dollar'},
1389 {'code' : 'FKP', 'name' : 'Falkland Islands (Malvinas) Pound'},
1390 {'code' : 'GBP', 'name' : 'United Kingdom Pound'},
1391 {'code' : 'GEL', 'name' : 'Georgia Lari'},
1392 {'code' : 'GGP', 'name' : 'Guernsey Pound'},
1393 {'code' : 'GHS', 'name' : 'Ghana Cedi'},
1394 {'code' : 'GIP', 'name' : 'Gibraltar Pound'},
1395 {'code' : 'GMD', 'name' : 'Gambia Dalasi'},
1396 {'code' : 'GNF', 'name' : 'Guinea Franc'},
1397 {'code' : 'GTQ', 'name' : 'Guatemala Quetzal'},
1398 {'code' : 'GYD', 'name' : 'Guyana Dollar'},
1399 {'code' : 'HKD', 'name' : 'Hong Kong Dollar'},
1400 {'code' : 'HNL', 'name' : 'Honduras Lempira'},
1401 {'code' : 'HRK', 'name' : 'Croatia Kuna'},
1402 {'code' : 'HTG', 'name' : 'Haiti Gourde'},
1403 {'code' : 'HUF', 'name' : 'Hungary Forint'},
1404 {'code' : 'IDR', 'name' : 'Indonesia Rupiah'},
1405 {'code' : 'ILS', 'name' : 'Israel Shekel'},
1406 {'code' : 'IMP', 'name' : 'Isle of Man Pound'},
1407 {'code' : 'INR', 'name' : 'India Rupee'},
1408 {'code' : 'IQD', 'name' : 'Iraq Dinar'},
1409 {'code' : 'IRR', 'name' : 'Iran Rial'},
1410 {'code' : 'ISK', 'name' : 'Iceland Krona'},
1411 {'code' : 'JEP', 'name' : 'Jersey Pound'},
1412 {'code' : 'JMD', 'name' : 'Jamaica Dollar'},
1413 {'code' : 'JOD', 'name' : 'Jordan Dinar'},
1414 {'code' : 'JPY', 'name' : 'Japan Yen'},
1415 {'code' : 'KES', 'name' : 'Kenya Shilling'},
1416 {'code' : 'KGS', 'name' : 'Kyrgyzstan Som'},
1417 {'code' : 'KHR', 'name' : 'Cambodia Riel'},
1418 {'code' : 'KMF', 'name' : 'Comoros Franc'},
1419 {'code' : 'KPW', 'name' : 'Korea (North) Won'},
1420 {'code' : 'KRW', 'name' : 'Korea (South) Won'},
1421 {'code' : 'KWD', 'name' : 'Kuwait Dinar'},
1422 {'code' : 'KYD', 'name' : 'Cayman Islands Dollar'},
1423 {'code' : 'KZT', 'name' : 'Kazakhstan Tenge'},
1424 {'code' : 'LAK', 'name' : 'Laos Kip'},
1425 {'code' : 'LBP', 'name' : 'Lebanon Pound'},
1426 {'code' : 'LKR', 'name' : 'Sri Lanka Rupee'},
1427 {'code' : 'LRD', 'name' : 'Liberia Dollar'},
1428 {'code' : 'LSL', 'name' : 'Lesotho Loti'},
1429 {'code' : 'LTL', 'name' : 'Lithuania Litas'},
1430 {'code' : 'LYD', 'name' : 'Libya Dinar'},
1431 {'code' : 'MAD', 'name' : 'Morocco Dirham'},
1432 {'code' : 'MDL', 'name' : 'Moldova Leu'},
1433 {'code' : 'MGA', 'name' : 'Madagascar Ariary'},
1434 {'code' : 'MKD', 'name' : 'Macedonia Denar'},
1435 {'code' : 'MMK', 'name' : 'Myanmar (Burma) Kyat'},
1436 {'code' : 'MNT', 'name' : 'Mongolia Tughrik'},
1437 {'code' : 'MOP', 'name' : 'Macau Pataca'},
1438 {'code' : 'MRO', 'name' : 'Mauritania Ouguiya'},
1439 {'code' : 'MUR', 'name' : 'Mauritius Rupee'},
1440 {'code' : 'MVR', 'name' : 'Maldives (Maldive Islands) Rufiyaa'},
1441 {'code' : 'MWK', 'name' : 'Malawi Kwacha'},
1442 {'code' : 'MXN', 'name' : 'Mexico Peso'},
1443 {'code' : 'MYR', 'name' : 'Malaysia Ringgit'},
1444 {'code' : 'MZN', 'name' : 'Mozambique Metical'},
1445 {'code' : 'NAD', 'name' : 'Namibia Dollar'},
1446 {'code' : 'NGN', 'name' : 'Nigeria Naira'},
1447 {'code' : 'NIO', 'name' : 'Nicaragua Cordoba'},
1448 {'code' : 'NOK', 'name' : 'Norway Krone'},
1449 {'code' : 'NPR', 'name' : 'Nepal Rupee'},
1450 {'code' : 'NZD', 'name' : 'New Zealand Dollar'},
1451 {'code' : 'OMR', 'name' : 'Oman Rial'},
1452 {'code' : 'PAB', 'name' : 'Panama Balboa'},
1453 {'code' : 'PEN', 'name' : 'Peru Nuevo Sol'},
1454 {'code' : 'PGK', 'name' : 'Papua New Guinea Kina'},
1455 {'code' : 'PHP', 'name' : 'Philippines Peso'},
1456 {'code' : 'PKR', 'name' : 'Pakistan Rupee'},
1457 {'code' : 'PLN', 'name' : 'Poland Zloty'},
1458 {'code' : 'PYG', 'name' : 'Paraguay Guarani'},
1459 {'code' : 'QAR', 'name' : 'Qatar Riyal'},
1460 {'code' : 'RON', 'name' : 'Romania New Leu'},
1461 {'code' : 'RSD', 'name' : 'Serbia Dinar'},
1462 {'code' : 'RUB', 'name' : 'Russia Ruble'},
1463 {'code' : 'RWF', 'name' : 'Rwanda Franc'},
1464 {'code' : 'SAR', 'name' : 'Saudi Arabia Riyal'},
1465 {'code' : 'SBD', 'name' : 'Solomon Islands Dollar'},
1466 {'code' : 'SCR', 'name' : 'Seychelles Rupee'},
1467 {'code' : 'SDG', 'name' : 'Sudan Pound'},
1468 {'code' : 'SEK', 'name' : 'Sweden Krona'},
1469 {'code' : 'SGD', 'name' : 'Singapore Dollar'},
1470 {'code' : 'SHP', 'name' : 'Saint Helena Pound'},
1471 {'code' : 'SLL', 'name' : 'Sierra Leone Leone'},
1472 {'code' : 'SOS', 'name' : 'Somalia Shilling'},
1473 {'code' : 'SPL', 'name' : 'Seborga Luigino'},
1474 {'code' : 'SRD', 'name' : 'Suriname Dollar'},
1475 {'code' : 'STD', 'name' : 'São Tomé and Príncipe Dobra'},
1476 {'code' : 'SVC', 'name' : 'El Salvador Colon'},
1477 {'code' : 'SYP', 'name' : 'Syria Pound'},
1478 {'code' : 'SZL', 'name' : 'Swaziland Lilangeni'},
1479 {'code' : 'THB', 'name' : 'Thailand Baht'},
1480 {'code' : 'TJS', 'name' : 'Tajikistan Somoni'},
1481 {'code' : 'TMT', 'name' : 'Turkmenistan Manat'},
1482 {'code' : 'TND', 'name' : 'Tunisia Dinar'},
1483 {'code' : 'TOP', 'name' : 'Tonga Pa\'anga'},
1484 {'code' : 'TRY', 'name' : 'Turkey Lira'},
1485 {'code' : 'TTD', 'name' : 'Trinidad and Tobago Dollar'},
1486 {'code' : 'TVD', 'name' : 'Tuvalu Dollar'},
1487 {'code' : 'TWD', 'name' : 'Taiwan New Dollar'},
1488 {'code' : 'TZS', 'name' : 'Tanzania Shilling'},
1489 {'code' : 'UAH', 'name' : 'Ukraine Hryvnia'},
1490 {'code' : 'UGX', 'name' : 'Uganda Shilling'},
1491 {'code' : 'USD', 'name' : 'United States Dollar'},
1492 {'code' : 'UYU', 'name' : 'Uruguay Peso'},
1493 {'code' : 'UZS', 'name' : 'Uzbekistan Som'},
1494 {'code' : 'VEF', 'name' : 'Venezuela Bolivar'},
1495 {'code' : 'VND', 'name' : 'Viet Nam Dong'},
1496 {'code' : 'VUV', 'name' : 'Vanuatu Vatu'},
1497 {'code' : 'WST', 'name' : 'Samoa Tala'},
1498 {'code' : 'XAF', 'name' : 'Communauté Financière Africaine (BEAC) CFA Franc BEAC'},
1499 {'code' : 'XCD', 'name' : 'East Caribbean Dollar'},
1500 {'code' : 'XDR', 'name' : 'International Monetary Fund (IMF) Special Drawing Rights'},
1501 {'code' : 'XOF', 'name' : 'Communauté Financière Africaine (BCEAO) Franc'},
1502 {'code' : 'XPF', 'name' : 'Comptoirs Français du Pacifique (CFP) Franc'},
1503 {'code' : 'YER', 'name' : 'Yemen Rial'},
1504 {'code' : 'ZAR', 'name' : 'South Africa Rand'},
1505 {'code' : 'ZMW', 'name' : 'Zambia Kwacha'},
1506 {'code' : 'ZWD', 'name' : 'Zimbabwe Dollar'}
1507 ]
1508 };
1509
1510 var o_hasOwnProperty = Object.prototype.hasOwnProperty;
1511 var o_keys = (Object.keys || function(obj) {
1512 var result = [];
1513 for (var key in obj) {
1514 if (o_hasOwnProperty.call(obj, key)) {
1515 result.push(key);
1516 }
1517 }
1518
1519 return result;
1520 });
1521
1522 function _copyObject(source, target) {
1523 var keys = o_keys(source);
1524
1525 for (var i = 0, l = keys.length; i < l; i++) {
1526 key = keys[i];
1527 target[key] = source[key] || target[key];
1528 }
1529 }
1530
1531 function _copyArray(source, target) {
1532 for (var i = 0, l = source.length; i < l; i++) {
1533 target[i] = source[i];
1534 }
1535 }
1536
1537 function copyObject(source, _target) {
1538 var isArray = Array.isArray(source);
1539 var target = _target || (isArray ? new Array(source.length) : {});
1540
1541 if (isArray) {
1542 _copyArray(source, target);
1543 } else {
1544 _copyObject(source, target);
1545 }
1546
1547 return target;
1548 }
1549
1550 /** Get the data based on key**/
1551 Chance.prototype.get = function (name) {
1552 return copyObject(data[name]);
1553 };
1554
1555 // Mac Address
1556 Chance.prototype.mac_address = function(options){
1557 // typically mac addresses are separated by ":"
1558 // however they can also be separated by "-"
1559 // the network variant uses a dot every fourth byte
1560
1561 options = initOptions(options);
1562 if(!options.separator) {
1563 options.separator = options.networkVersion ? "." : ":";
1564 }
1565
1566 var mac_pool="ABCDEF1234567890",
1567 mac = "";
1568 if(!options.networkVersion) {
1569 mac = this.n(this.string, 6, { pool: mac_pool, length:2 }).join(options.separator);
1570 } else {
1571 mac = this.n(this.string, 3, { pool: mac_pool, length:4 }).join(options.separator);
1572 }
1573
1574 return mac;
1575 };
1576
1577 Chance.prototype.normal = function (options) {
1578 options = initOptions(options, {mean : 0, dev : 1});
1579
1580 // The Marsaglia Polar method
1581 var s, u, v, norm,
1582 mean = options.mean,
1583 dev = options.dev;
1584
1585 do {
1586 // U and V are from the uniform distribution on (-1, 1)
1587 u = this.random() * 2 - 1;
1588 v = this.random() * 2 - 1;
1589
1590 s = u * u + v * v;
1591 } while (s >= 1);
1592
1593 // Compute the standard normal variate
1594 norm = u * Math.sqrt(-2 * Math.log(s) / s);
1595
1596 // Shape and scale
1597 return dev * norm + mean;
1598 };
1599
1600 Chance.prototype.radio = function (options) {
1601 // Initial Letter (Typically Designated by Side of Mississippi River)
1602 options = initOptions(options, {side : "?"});
1603 var fl = "";
1604 switch (options.side.toLowerCase()) {
1605 case "east":
1606 case "e":
1607 fl = "W";
1608 break;
1609 case "west":
1610 case "w":
1611 fl = "K";
1612 break;
1613 default:
1614 fl = this.character({pool: "KW"});
1615 break;
1616 }
1617
1618 return fl + this.character({alpha: true, casing: "upper"}) +
1619 this.character({alpha: true, casing: "upper"}) +
1620 this.character({alpha: true, casing: "upper"});
1621 };
1622
1623 // Set the data as key and data or the data map
1624 Chance.prototype.set = function (name, values) {
1625 if (typeof name === "string") {
1626 data[name] = values;
1627 } else {
1628 data = copyObject(name, data);
1629 }
1630 };
1631
1632 Chance.prototype.tv = function (options) {
1633 return this.radio(options);
1634 };
1635
1636 // ID number for Brazil companies
1637 Chance.prototype.cnpj = function () {
1638 var n = this.n(this.natural, 8, { max: 9 });
1639 var d1 = 2+n[7]*6+n[6]*7+n[5]*8+n[4]*9+n[3]*2+n[2]*3+n[1]*4+n[0]*5;
1640 d1 = 11 - (d1 % 11);
1641 if (d1>=10){
1642 d1 = 0;
1643 }
1644 var d2 = d1*2+3+n[7]*7+n[6]*8+n[5]*9+n[4]*2+n[3]*3+n[2]*4+n[1]*5+n[0]*6;
1645 d2 = 11 - (d2 % 11);
1646 if (d2>=10){
1647 d2 = 0;
1648 }
1649 return ''+n[0]+n[1]+'.'+n[2]+n[3]+n[4]+'.'+n[5]+n[6]+n[7]+'/0001-'+d1+d2;
1650 };
1651
1652 // -- End Miscellaneous --
1653
1654 Chance.prototype.mersenne_twister = function (seed) {
1655 return new MersenneTwister(seed);
1656 };
1657
1658 // Mersenne Twister from https://gist.github.com/banksean/300494
1659 var MersenneTwister = function (seed) {
1660 if (seed === undefined) {
1661 seed = new Date().getTime();
1662 }
1663 /* Period parameters */
1664 this.N = 624;
1665 this.M = 397;
1666 this.MATRIX_A = 0x9908b0df; /* constant vector a */
1667 this.UPPER_MASK = 0x80000000; /* most significant w-r bits */
1668 this.LOWER_MASK = 0x7fffffff; /* least significant r bits */
1669
1670 this.mt = new Array(this.N); /* the array for the state vector */
1671 this.mti = this.N + 1; /* mti==N + 1 means mt[N] is not initialized */
1672
1673 this.init_genrand(seed);
1674 };
1675
1676 /* initializes mt[N] with a seed */
1677 MersenneTwister.prototype.init_genrand = function (s) {
1678 this.mt[0] = s >>> 0;
1679 for (this.mti = 1; this.mti < this.N; this.mti++) {
1680 s = this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30);
1681 this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253) + this.mti;
1682 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
1683 /* In the previous versions, MSBs of the seed affect */
1684 /* only MSBs of the array mt[]. */
1685 /* 2002/01/09 modified by Makoto Matsumoto */
1686 this.mt[this.mti] >>>= 0;
1687 /* for >32 bit machines */
1688 }
1689 };
1690
1691 /* initialize by an array with array-length */
1692 /* init_key is the array for initializing keys */
1693 /* key_length is its length */
1694 /* slight change for C++, 2004/2/26 */
1695 MersenneTwister.prototype.init_by_array = function (init_key, key_length) {
1696 var i = 1, j = 0, k, s;
1697 this.init_genrand(19650218);
1698 k = (this.N > key_length ? this.N : key_length);
1699 for (; k; k--) {
1700 s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30);
1701 this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525))) + init_key[j] + j; /* non linear */
1702 this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
1703 i++;
1704 j++;
1705 if (i >= this.N) { this.mt[0] = this.mt[this.N - 1]; i = 1; }
1706 if (j >= key_length) { j = 0; }
1707 }
1708 for (k = this.N - 1; k; k--) {
1709 s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30);
1710 this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941)) - i; /* non linear */
1711 this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
1712 i++;
1713 if (i >= this.N) { this.mt[0] = this.mt[this.N - 1]; i = 1; }
1714 }
1715
1716 this.mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
1717 };
1718
1719 /* generates a random number on [0,0xffffffff]-interval */
1720 MersenneTwister.prototype.genrand_int32 = function () {
1721 var y;
1722 var mag01 = new Array(0x0, this.MATRIX_A);
1723 /* mag01[x] = x * MATRIX_A for x=0,1 */
1724
1725 if (this.mti >= this.N) { /* generate N words at one time */
1726 var kk;
1727
1728 if (this.mti === this.N + 1) { /* if init_genrand() has not been called, */
1729 this.init_genrand(5489); /* a default initial seed is used */
1730 }
1731 for (kk = 0; kk < this.N - this.M; kk++) {
1732 y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk + 1]&this.LOWER_MASK);
1733 this.mt[kk] = this.mt[kk + this.M] ^ (y >>> 1) ^ mag01[y & 0x1];
1734 }
1735 for (;kk < this.N - 1; kk++) {
1736 y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk + 1]&this.LOWER_MASK);
1737 this.mt[kk] = this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ mag01[y & 0x1];
1738 }
1739 y = (this.mt[this.N - 1]&this.UPPER_MASK)|(this.mt[0]&this.LOWER_MASK);
1740 this.mt[this.N - 1] = this.mt[this.M - 1] ^ (y >>> 1) ^ mag01[y & 0x1];
1741
1742 this.mti = 0;
1743 }
1744
1745 y = this.mt[this.mti++];
1746
1747 /* Tempering */
1748 y ^= (y >>> 11);
1749 y ^= (y << 7) & 0x9d2c5680;
1750 y ^= (y << 15) & 0xefc60000;
1751 y ^= (y >>> 18);
1752
1753 return y >>> 0;
1754 };
1755
1756 /* generates a random number on [0,0x7fffffff]-interval */
1757 MersenneTwister.prototype.genrand_int31 = function () {
1758 return (this.genrand_int32() >>> 1);
1759 };
1760
1761 /* generates a random number on [0,1]-real-interval */
1762 MersenneTwister.prototype.genrand_real1 = function () {
1763 return this.genrand_int32() * (1.0 / 4294967295.0);
1764 /* divided by 2^32-1 */
1765 };
1766
1767 /* generates a random number on [0,1)-real-interval */
1768 MersenneTwister.prototype.random = function () {
1769 return this.genrand_int32() * (1.0 / 4294967296.0);
1770 /* divided by 2^32 */
1771 };
1772
1773 /* generates a random number on (0,1)-real-interval */
1774 MersenneTwister.prototype.genrand_real3 = function () {
1775 return (this.genrand_int32() + 0.5) * (1.0 / 4294967296.0);
1776 /* divided by 2^32 */
1777 };
1778
1779 /* generates a random number on [0,1) with 53-bit resolution*/
1780 MersenneTwister.prototype.genrand_res53 = function () {
1781 var a = this.genrand_int32()>>>5, b = this.genrand_int32()>>>6;
1782 return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
1783 };
1784
1785
1786 // CommonJS module
1787 if (typeof exports !== 'undefined') {
1788 if (typeof module !== 'undefined' && module.exports) {
1789 exports = module.exports = Chance;
1790 }
1791 exports.Chance = Chance;
1792 }
1793
1794 // Register as an anonymous AMD module
1795 if (typeof define === 'function' && define.amd) {
1796 define([], function () {
1797 return Chance;
1798 });
1799 }
1800
1801 // if there is a importsScrips object define chance for worker
1802 if (typeof importScripts !== 'undefined') {
1803 chance = new Chance();
1804 }
1805
1806 // If there is a window object, that at least has a document property,
1807 // instantiate and define chance on the window
1808 if (typeof window === "object" && typeof window.document === "object") {
1809 window.Chance = Chance;
1810 window.chance = new Chance();
1811 }
1812})();