Generate a Random Hex Color Code
Sometimes I find myself in a random scenario needing a random hex color, or a good way to generate a lot of them very quickly. This method does exactly that. Call it, you get a completely random hex.
Sometimes I find myself in a random scenario needing a random hex color, or a good way to generate a lot of them very quickly. This method does exactly that. Call it, you get a completely random hex.
function randomHexColor(){
var hexChars = "0123456789ABCDEF".split("");
var color = "#";
// We want 6 random characters to make a color
for(var i = 0; i < 6; i++){
// Math.random returns number between 0 and 1
// there are 16 indexes in the hexChar array
color += hexChars[Math.round(Math.random()*15)];
}
return color;
}