Skip to content

Instantly share code, notes, and snippets.

@ncole458
Created February 11, 2016 13:12
Show Gist options
  • Save ncole458/69620c93a95099d7546f to your computer and use it in GitHub Desktop.
Save ncole458/69620c93a95099d7546f to your computer and use it in GitHub Desktop.
UUID / GUID in JavaScript
// https://en.wikipedia.org/wiki/Universally_unique_identifier
// https://en.wikipedia.org/wiki/Globally_unique_identifier
// No hyphens (-) in below but can be add in the 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'
var uuid = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
console.log(uuid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment