Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created January 13, 2017 19:19
Show Gist options
  • Save lukemelia/9daf074b1b2dfebc0bd87552d0f6a537 to your computer and use it in GitHub Desktop.
Save lukemelia/9daf074b1b2dfebc0bd87552d0f6a537 to your computer and use it in GitHub Desktop.
uuid gen
export function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r, v;
r = Math.random() * 16 | 0;
v = c === 'x' ? r : r & 3 | 8;
return v.toString(16);
});
}
@dirtyhenry
Copy link

Why the 4 and the y?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment