Skip to content

Instantly share code, notes, and snippets.

@alexpilugin
Created July 23, 2018 21:15
Show Gist options
  • Save alexpilugin/3fd7eae4b44184c830b4652f4204993d to your computer and use it in GitHub Desktop.
Save alexpilugin/3fd7eae4b44184c830b4652f4204993d to your computer and use it in GitHub Desktop.
Generate Unique ID v4
function generateUUID() {
let d = new Date().getTime()
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
})
return uuid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment