PHP Random colour generator
I was thinking the other day that it might be fun to have a different colour generated every time a page loads. Can’t be that difficult, just some random variables made into a string. concatenating six variables seemed a little on the clumsy side so I had a look round online and found this great example by Jonas John (The code looks much prettier on his site!). The result can be seen top right of this page.
1 2 3 4 5 6 7 8 | function random_color(){ mt_srand((double)microtime()*1000000); $c = ''; while(strlen($c)<6){ $c .= sprintf("%02X", mt_rand(0, 255)); } return $c; } |