Just to add some lines to NogDog's code...
*** WARMING : you MUST put some code in the Is_Color_Unique() function, otherwise the script will never end/time out ! You have been warned !
function Is_Color_Unique($strColor) {
$bolIs_Unique = false;
// some code to check if color is unique
// Will set $bolIs_Unique to true only if the color is unique
return $bolIs_Unique;
}
function Generate_Color() {
return sprintf('#%02X%02X%02X', rand(0, 255), rand(0, 255), rand(0, 255));
}
$strColor = Generate_Color();
while(!Is_Color_Unique($strColor)) {
$strColor = Generate_Color();
}