Skip to content

Instantly share code, notes, and snippets.

@neftaly
Last active November 25, 2017 22:04
Show Gist options
  • Select an option

  • Save neftaly/26f27d01daee048794dd to your computer and use it in GitHub Desktop.

Select an option

Save neftaly/26f27d01daee048794dd to your computer and use it in GitHub Desktop.
Javascript random UUID generator
// 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