Created
September 16, 2018 17:31
-
-
Save hlfbt/638105da1aa65ba5ab5a2f447181eed0 to your computer and use it in GitHub Desktop.
Generate random GUIDs usable as element IDs (first character is always a letter)
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
(function () { | |
var S4 = function (n, d) { | |
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) + (n > 1 ? (d || '') + S4(n - 1, d) : ''); | |
}; | |
return (String.fromCharCode(97 + Math.floor(Math.random() * 26)) + S4().substring(1) + S4(5, '-') + S4(2)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment