Possible Duplicate:
Random Color generator in Javascript
I have some data I'd like to display in different colors and I want to generate the colors randomly if possible. How can I generate the Hex Color Code using JavaScript?
var randomColor = Math. floor(Math. random()*16777215).
This will generate a random number within the bounds and convert it to hexadecimal. It is then padded with zeros so that it's always a valid six-digit hex code.
'#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With