Skip to content

Instantly share code, notes, and snippets.

@tjadhav
Last active June 11, 2018 07:13
Show Gist options
  • Save tjadhav/7681b6fb59f07bc78441669d242cb227 to your computer and use it in GitHub Desktop.
Save tjadhav/7681b6fb59f07bc78441669d242cb227 to your computer and use it in GitHub Desktop.
UUID Generator
// https://medium.com/@ideepak.jsd/javascript-generator-yield-next-async-await-e428b0cb52e4
function* UUIDGenerator() {
let d, r;
while (true) {
yield 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
r = (new Date().getTime() + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment