d
Amit DhamuSoftware Engineer
 

Generate Random Colour

1 minute read 00000 views
$rand = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];

$random_colour = '#' . $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];

Also, an alternate one-liner:

$random_colour = '#' . strtoupper(dechex(rand(0,10000000)));