Skip to content

Instantly share code, notes, and snippets.

@electerious
Created August 11, 2017 16:25
Show Gist options
  • Save electerious/46ae766fa7ba6262d3203efba756aeb3 to your computer and use it in GitHub Desktop.
Save electerious/46ae766fa7ba6262d3203efba756aeb3 to your computer and use it in GitHub Desktop.
Generate a random hsl color
const randomColor = () => {
const random = (min, max) => Math.random() * (max - min) + min
const h = Math.floor(random(0, 360))
const s = Math.floor(random(50, 100))
const l = Math.floor(random(50, 100))
return `hsl(${ h }, ${ s }%, ${ l }%)`
}
@electerious
Copy link
Author

Example:

randomColor() // hsl(241, 66, 87)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment