Last active
February 20, 2018 16:34
-
-
Save adames/4c408f6d2464349f6199ab7b890c116c to your computer and use it in GitHub Desktop.
UUID Generator (https://stackoverflow.com/a/8809472)
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
function generateUUID () { | |
let time = new Date().getTime(); | |
if (typeof performance !== 'undefined' && typeof performance.now === 'function'){ | |
time += performance.now(); | |
} | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | |
let random = (time + Math.random() * 16) % 16 | 0; | |
time = Math.floor(time / 16); | |
return (c === 'x' ? random : (random & 0x3 | 0x8)).toString(16); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment