Generate A Random Colour With PHP
Published by philipnorton42 on Wed, 05/21/2008 - 09:35Here is a short bit of code to generate a random hexadecimal colour using PHP. Essentially you just create a random number between 0 (000000) and 10,000,000 (ffffff) and turn this into a hexadecimal number using the PHP function dechex.
This can also be accomplished on a single line.
$colour = dechex(rand(0, 10000000));Category:
Add new comment