Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created May 8, 2013 21:40
Show Gist options
  • Save marti1125/5543889 to your computer and use it in GitHub Desktop.
Save marti1125/5543889 to your computer and use it in GitHub Desktop.
UUID Generator in JavaScript
function randomUUID() {
var s = [], itoh = '0123456789ABCDEF';
for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
s[14] = 4;
s[19] = (s[19] & 0x3) | 0x8;
for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
s[8] = s[13] = s[18] = s[23] = '-';
return s.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment