Want a random colour between white and black?
"#" + (Math.random() * 0xffffff | 0).toString(16)
That is all.
[Update: after I posted this I thought... i bet this has been done a zillion times already. It was, and by Paul Irish in 2009 no less. Additionally - it doesn't work. The best looking one there was:
'#'+('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);
3 Comments
Alternatively, you can use the css3 rgb(x, x, x) or rgba(x, x, x, y) where x are random numbers between 0,255 and you is 0.1,0.9. Can’t type the actually code r easily on my phone, but that’s how I do it.
If you can do 3 random numbers between 0 and 255 in less than 63 characters… I wanna see the code!
I stumbled upon this nice piece of code and was wondering that one could achieve any tone between white and black by randomizing only values between 0.0 … 1.0 and have a color of black, alpha set to random variable? short enough? :)