Skip to content

Instantly share code, notes, and snippets.

@MarvinJWendt
Created October 22, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarvinJWendt/72b02fd42232f03a5d02e7ae6ff318e9 to your computer and use it in GitHub Desktop.
Save MarvinJWendt/72b02fd42232f03a5d02e7ae6ff318e9 to your computer and use it in GitHub Desktop.
Generates an UUID in JavaScript
function generateUUID() {
var date = new Date().getTime();
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
date += performance.now();
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var random = (date + Math.random() * 16) % 16 | 0;
date = Math.floor(date / 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