php,用rand生成红黄蓝绿紫这五个颜色随机重复,怎样才能使同一时间内这五个颜色没有重复的,都不

php,用rand生成红黄蓝绿紫这五个颜色随机重复,怎样才能使同一时间内这五个颜色没有重复的,都不相同?

<?php
function randColor($num){
//color value limits 0-16777215;
$prehash='#'; //using string '#' before the color value;
$rsArr=array();
for($i=0;$i<$num;$i++){
$color=rand(0,16777215);
$rsArr[$i]=$prehash.str_pad(dechex($color),6,"0",STR_PAD_LEFT);
}
return $rsArr;
}
print_r(randColor(20));
?>
温馨提示:答案为网友推荐,仅供参考