Created
October 22, 2017 01:09
-
-
Save MarvinJWendt/72b02fd42232f03a5d02e7ae6ff318e9 to your computer and use it in GitHub Desktop.
Generates an UUID in JavaScript
This file contains hidden or 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() { | |
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