Skip to content

Instantly share code, notes, and snippets.

@mauris
Created September 6, 2012 01:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mauris/3649712 to your computer and use it in GitHub Desktop.
Save mauris/3649712 to your computer and use it in GitHub Desktop.
Distinctive Random Colour Generation
function randomColor($id){
$rawR = mt_rand(0, 10) * 25.5;
$rawG = mt_rand(0, 10) * 25.5;
$rawB = mt_rand(0, 10) * 25.5;
$mix = ceil(($id % 5) / 5 * 255);
$r = ceil(($rawR + $mix) % 255);
$g = ceil(($rawG + $mix) % 255);
$b = ceil(($rawB + $mix) % 255);
return str_pad(dechex(($r << 16) | ($g << 8) | $b), 6, '0', STR_PAD_LEFT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment