Tuesday, September 16, 2008

Generate a random tint using PHP

I found this to be a brilliant solution for quickly generating a random background colour, ideal for report a graph with lots of bars...

echo dechex(rand(1,10000000)));

I need it to still be legible so used the following to strip out the darker colours...

echo str_replace(array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"),"A",dechex(rand(1,10000000)));

No comments: