Skip to content

Instantly share code, notes, and snippets.

@lukem512
Created January 7, 2020 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukem512/327e424da8a1c8b573479dee6b7bec2a to your computer and use it in GitHub Desktop.
Save lukem512/327e424da8a1c8b573479dee6b7bec2a to your computer and use it in GitHub Desktop.
Generate a random hexadecimal colour code in JavaScript
// Function to generate a 24-bit (non-alpha) colour (color, for US English speakers)
function makeRandomColour() {
const MAX_INT24 = 16777215;
return '#' + Math.round(Math.random() * MAX_INT24).toString(16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment