Skip to content

Instantly share code, notes, and snippets.

@adames
Last active February 20, 2018 16:34
Show Gist options
  • Save adames/4c408f6d2464349f6199ab7b890c116c to your computer and use it in GitHub Desktop.
Save adames/4c408f6d2464349f6199ab7b890c116c to your computer and use it in GitHub Desktop.
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