Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some codegolfing I did, along with the progress
// random hex
'#'+Math.random().toString(16).slice(-6)
'#'+(~~(Math.random()*0xffffff)).toString(16)
'#'+parseInt(Math.random()*0xffffff).toString(16)
// random rgb
r=_=>(Math.random()*255|0),`rgb(${[r(),r(),r()]})`
// random rgba
r=_=>(Math.random()*255|0),`rgba(${[r(),r(),r()]},1)`
r=_=>(Math.random()*255|0)+',',`rgba(${r()+r()+r()}1)`
r=Math.random,a=_=>(r()*255|0)+',',`rgba(${a()+a()+a()}1)`
r=Math.random,a=_=>~~(r()*255)+',',`rgba(${a()+a()+a()}1)`
r=Math.random,a=_=>~~(r()*255)+',',x=a()+a()+a(),`rgba(${x}1)`
// rgb to hex - es6 version of https://gist.github.com/jed/983535
(a,b,c)=>"#"+((256+a<<8|b)<<8|c).toString(16).slice(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.