Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Created August 5, 2018 13:15
Show Gist options
  • Save TravisMullen/3e19f15b8e7c17b954e55c1302bf462c to your computer and use it in GitHub Desktop.
Save TravisMullen/3e19f15b8e7c17b954e55c1302bf462c to your computer and use it in GitHub Desktop.
Generate a random hex value.
const hexGenerator = function(length = 16) {
let text = "";
const possible = "ABCDEFabcdef0123456789";
for(let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
// convert to random with parseInt(`0x${hexGenerator()}`, 16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment