forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.js
139 lines (105 loc) · 3.52 KB
/
random.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var definitions = require('./definitions');
var mersenne = require('../vendor/mersenne');
var faker = require('../index');
var random = {
// returns a single random number based on a max number or range
number: function (options) {
if (typeof options === "number") {
var options = {
max: options
};
}
options = options || {
min: 0,
max: 1,
precision: 1
};
if (typeof options.min === "undefined") {
options.min = 0;
}
if (typeof options.max === "undefined") {
options.max = 1;
}
// by incrementing max by 1, max becomes inclusive of the range
if (options.max > 0) {
options.max++;
}
var randomNumber = mersenne.rand(options.max, options.min);
return randomNumber;
},
// takes an array and returns the array randomly sorted
array_element: function (array) {
var r = faker.random.number({ max: array.length -1 });
return array[r];
},
city_prefix: function () {
return faker.random.array_element(definitions.city_prefix);
},
city_suffix: function () {
return faker.random.array_element(definitions.city_suffix);
},
street_suffix: function () {
return faker.random.array_element(definitions.street_suffix);
},
br_state: function () {
return faker.random.array_element(definitions.br_state);
},
br_state_abbr: function () {
return faker.random.array_element(definitions.br_state_abbr);
},
us_state: function () {
return faker.random.array_element(definitions.us_state);
},
us_state_abbr: function () {
return faker.random.array_element(definitions.us_state_abbr);
},
uk_county: function () {
return faker.random.array_element(definitions.uk_county);
},
uk_country: function () {
return faker.random.array_element(definitions.uk_country);
},
first_name: function () {
return faker.random.array_element(definitions.first_name);
},
last_name: function () {
return faker.random.array_element(definitions.last_name);
},
name_prefix: function () {
return faker.random.array_element(definitions.name_prefix);
},
name_suffix: function () {
return faker.random.array_element(definitions.name_suffix);
},
catch_phrase_adjective: function () {
return faker.random.array_element(definitions.catch_phrase_adjective);
},
catch_phrase_descriptor: function () {
return faker.random.array_element(definitions.catch_phrase_descriptor);
},
catch_phrase_noun: function () {
return faker.random.array_element(definitions.catch_phrase_noun);
},
bs_adjective: function () {
return faker.random.array_element(definitions.bs_adjective);
},
bs_buzz: function () {
return faker.random.array_element(definitions.bs_buzz);
},
bs_noun: function () {
return faker.random.array_element(definitions.bs_noun);
},
phone_formats: function () {
return faker.random.array_element(definitions.phone_formats);
},
phone_codes: function () {
return faker.random.array_element(definitions.phone_codes);
},
domain_suffix: function () {
return faker.random.array_element(definitions.domain_suffix);
},
avatar_uri: function () {
return faker.random.array_element(definitions.avatar_uri);
}
};
module.exports = random;