I have this code:
function rand_colorCode(){
$r = dechex(mt_rand(0,255));
$g = dechex(mt_rand(0,255));
$b = dechex(mt_rand(0,255));
$rgb = $r.$g.$b;
if($r == $g && $g == $b){
$rgb = substr($rgb,0,3);
}
return '#'.$rgb;
}
$code = rand_colorCode();
This generates a random color which later gets inserted into the mysql db. But sometimes it generates too light color. (this is a problem because these colors are later displayed and my background color is white)
My simple question is: How can I prevent colors being too light or too dark? How should I customize my code?