Created
December 26, 2018 03:04
-
-
Save mustofa-id/b358e89cbc2a7d77e2f47442791e90a2 to your computer and use it in GitHub Desktop.
Generate random GUID using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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