PDA

View Full Version : how to generate unique hexcolors ??


PHPycho
04-13-2007, 05:14 AM
Hello forums !!
I am getting problem in generating unique hexcolors ie #XXXXXX
Can anybody provide me the help regarding generation of unique hexcolors ??
Thanks to all of You in advance..

david_kw
04-13-2007, 05:34 AM
I can only speak for myself, but I really have no idea what you are asking for. What do you mean you have to generate unique hexcolors?

Some sample code might be helpful.

david_kw

Fumigator
04-13-2007, 06:35 AM
Do you mean a random hex value for an RGB color?

This will create a random hex RGB value as a string:

$randomColor = '#' .
sprintf("%02s", dechex(rand(0, 255))) .
sprintf("%02s", dechex(rand(0, 255))) .
sprintf("%02s", dechex(rand(0, 255)));

Len Whistler
04-13-2007, 05:17 PM
This is a code I used to generate a random background color and text.

<?php

$r = rand(200,225);
$g = rand(200,225);
$b = rand(200,225);
$background = dechex($r) . dechex($g) . dechex($b);
$text = dechex($r-120) . dechex($g-120) . dechex($b-120);
?>

<?php
echo "<body bgcolor=\"#$background\">";
echo "<font color=\"#$text\">\n";
?>