Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created July 27, 2011 00:40
Show Gist options
  • Save huobazi/1108437 to your computer and use it in GitHub Desktop.
Save huobazi/1108437 to your computer and use it in GitHub Desktop.
Javascript generate a pseudo-GUID
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
function guid() {
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