Skip to content

Instantly share code, notes, and snippets.

@piranha
Created April 16, 2013 16:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/5397380 to your computer and use it in GitHub Desktop.
Save piranha/5397380 to your computer and use it in GitHub Desktop.
UUID4 (almost) in Javascript, for when you need some more or less unique id.
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function UUID(short) {
if (short) {
return S4() + S4();
}
return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment