I needed some PHP code to randomly generate me a hex value for use as a color in a webpage. Here’s what I came up with (WARNING: Some colors are UGLY!)
function random_hex() { $color = ''; for ($c = 0; $c < 6; $c++) { $i = rand(0, 15); switch ($i) { case 10 : $i = 'A'; break; case 11 : $i = 'B'; break; case 12 : $i = 'C'; break; case 13 : $i = 'D'; break; case 14 : $i = 'E'; break; case 15 : $i = 'F'; break; default : $i = $i; break; } $color .= $i; } $color = '#' . $color; return $color; }