aboutsummaryrefslogtreecommitdiff
path: root/lib/random.js
diff options
context:
space:
mode:
authorBryan Donovan <[email protected]>2013-01-05 19:54:21 -0800
committerBryan Donovan <[email protected]>2013-01-05 19:54:21 -0800
commit0b3cfbee64547e7a624c8d8f988c293ed463cf4b (patch)
tree46b926661b16b3eb8f911777c2fb8f699d8785f1 /lib/random.js
parent8a6ad8d2de768aff38e09cda46fc0dfd2d52b2b8 (diff)
downloadfaker-0b3cfbee64547e7a624c8d8f988c293ed463cf4b.tar.xz
faker-0b3cfbee64547e7a624c8d8f988c293ed463cf4b.zip
refactoring so we do not need to use Helpers.randomize() everywhere
Diffstat (limited to 'lib/random.js')
-rw-r--r--lib/random.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/random.js b/lib/random.js
new file mode 100644
index 00000000..abfba1a4
--- /dev/null
+++ b/lib/random.js
@@ -0,0 +1,34 @@
+var definitions = require('./definitions');
+
+var random = {
+ // returns a single random number based on a range
+ number: function (range) {
+ var r = Math.floor(Math.random() * range);
+ console.log(r);
+ return r;
+ },
+
+ // takes an array and returns the array randomly sorted
+ array_rand: function (array) {
+ var r = Math.floor(Math.random() * array.length);
+ return array[r];
+ }
+};
+
+var method_names = [
+ 'catch_phrase_adjective',
+ 'catch_phrase_descriptor',
+ 'catch_phrase_noun',
+ 'bs_adjective',
+ 'bs_buzz',
+ 'bs_noun'
+];
+
+for (var i = 0; i < method_names.length; i++) {
+ var method_name = method_names[i];
+ random[method_name] = function () {
+ return random.array_rand(definitions[method_name]());
+ };
+}
+
+module.exports = random;