Skip to content

Instantly share code, notes, and snippets.

@LukeberryPi
Created October 20, 2023 22:02
Show Gist options
  • Save LukeberryPi/216f694db1d4a4bab4053c1a2fb578c5 to your computer and use it in GitHub Desktop.
Save LukeberryPi/216f694db1d4a4bab4053c1a2fb578c5 to your computer and use it in GitHub Desktop.
function to generate a random hexcode
function generateRandomHexCode() {
const validChars = "abcdef0123456789";
let hexcode = "#";
for (let i = 0; i < 6; i++) {
const char = validChars[Math.floor(Math.random() * validChars.length)];
hexcode += char;
}
return hexcode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment