Skip to content

Commit

Permalink
Added function to generate UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew1303 committed Dec 22, 2014
1 parent 2a46c19 commit 0b38c25
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down

0 comments on commit 0b38c25

Please sign in to comment.