public
Last active

Guid generator in Javascript.

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(function(){
if(!window.String.UUID){
var matcher = /[xy]/g;
var replacer = function(c) {
var r = Math.random()*16|0;
var v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
};
//maybe shouldn't be modifying the global variable, but seems like the best place to put this.
window.String.UUID = function(){
//see http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript for more details.
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(matcher, replacer);
};
}
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.