Skip to content

Instantly share code, notes, and snippets.

@emukupa
Last active December 7, 2019 12:55
Show Gist options
  • Save emukupa/54e7dbd3e1d4aaf8f63e9d55aacac6c0 to your computer and use it in GitHub Desktop.
Save emukupa/54e7dbd3e1d4aaf8f63e9d55aacac6c0 to your computer and use it in GitHub Desktop.
const rgbColor = () => Math.floor(Math.random() * 256); // numbers betweer 0 - 255
// rgba === red, green, blue and alpha
// rgba examples: white rgba(255, 255, 255, 1), black rgba(0, 0, 0, 1)... etc
const randomRGBColor = (alpha = 1) => `rgba(${rgbColor()}, ${rgbColor()}, ${rgbColor()}, ${alpha})`;
// RESULTS
// rgba(204, 36, 145, 1), all values are random between 0 - 255, last value is definitely 1
console.log(randomColor());
// rgba(219, 106, 175, 0.5), all values are random between 0 - 255, last value is definitely 0.5
console.log(randomColor(0.5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment