aboutsummaryrefslogtreecommitdiff
path: root/lib/random.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/random.js')
-rw-r--r--lib/random.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/random.js b/lib/random.js
index 76cfbe90..3205d8c4 100644
--- a/lib/random.js
+++ b/lib/random.js
@@ -51,6 +51,16 @@ var random = {
var key = faker.random.array_element(array);
return field === "key" ? key : object[key];
+ },
+
+ uuid : function () {
+ var RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
+ var replacePlaceholders = function (placeholder) {
+ var random = Math.random()*16|0;
+ var value = placeholder == 'x' ? random : (random &0x3 | 0x8);
+ return value.toString(16);
+ };
+ return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders);
}
};