Skip to content

Instantly share code, notes, and snippets.

@libesto
Forked from kettuniko/randomcolors.js
Created July 30, 2020 01:19
Show Gist options
  • Save libesto/cff5a5a4fc77932e2f7f300bedd96a35 to your computer and use it in GitHub Desktop.
Save libesto/cff5a5a4fc77932e2f7f300bedd96a35 to your computer and use it in GitHub Desktop.
Random RGBA colors with javascript
const randomNumber = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
const randomByte = () => randomNumber(0, 255)
const randomPercent = () => (randomNumber(50, 100) * 0.01).toFixed(2)
const randomCssRgba = () => `rgba(${[randomByte(), randomByte(), randomByte(), randomPercent()].join(',')})`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment