Created
February 11, 2016 13:12
-
-
Save ncole458/69620c93a95099d7546f to your computer and use it in GitHub Desktop.
UUID / GUID in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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