Skip to content

Instantly share code, notes, and snippets.

@mustofa-id
Created December 26, 2018 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustofa-id/b358e89cbc2a7d77e2f47442791e90a2 to your computer and use it in GitHub Desktop.
Save mustofa-id/b358e89cbc2a7d77e2f47442791e90a2 to your computer and use it in GitHub Desktop.
Generate random GUID using JavaScript
// Generate random GUID
function guid() {
const rand = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
let res = rand();
for (let i = 0; i < 11; i++) {
i % 2 && i <= 7 ? (res += '-') : (res += rand());
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment