Last active
November 25, 2017 22:04
-
-
Save neftaly/26f27d01daee048794dd to your computer and use it in GitHub Desktop.
Javascript random UUID generator
This file contains hidden or 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
| // Random (type 4) UUID generator | |
| // Insecure if seed undefined | |
| var UUID = function(seed) { | |
| var UUID = ""; | |
| for (var i = 0 ; i < 36; i++) { | |
| UUID += (function (i) { | |
| if (i === 8 || i === 13 || i === 18 || i === 23) return "-"; | |
| if (i === 14) return "4"; // UUID version flag | |
| if (i === 19) return "8"; // Can be "8", "9", "A" or "B" | |
| return Math.floor( Math.random(seed) * 16 ).toString(16); | |
| })(i); | |
| } | |
| return UUID; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment