一个双色球随机数的生成方法,比较近十期的中奖号码,排除多次出现的号码
public function doubleBall(){
$ball['red'] = [];
$ball['blue'] =[];
$count = 0;
$last_red=[
[3,11,18,25,30,33],
[3,7,10,12,18,29],
[3,10,13,22,23,28],
[4,6,10,11,21,23],
[8,9,10,13,15,28],
[3,6,9,13,16,19],
[4,16,22,25,29,31],
[7,10,11,15,24,26],
[1,6,11,15,19,31],
[13,14,17,19,21,29],
];
$last_blue=[14,10,15,2,9,16,8,11,10,1];
do{
$rand_red = rand(1,33);
$appear = 0;
$contiue = 0;
foreach ($last_red as $key => $val){
if (in_array($rand_red,$val)){
$appear++;
if ($key>0){
if (in_array($rand_red,$last_red[$key-1]))
$contiue++;
}
}
}
if (!in_array($rand_red,$ball['red'])&&$appear<3&&$contiue<2){
$ball['red'][] = $rand_red;
}
$count = count($ball['red']);
if ($count == 6){
$type = 0;
}else{
$type = 1;
}
}while($type);
for ($i =0;$i<count($ball['red']);$i++){
for ($j = $i+1;$j<count($ball['red']);$j++){
if ($ball['red'][$i]>$ball['red'][$j]){
$item = $ball['red'][$j];
$ball['red'][$j] = $ball['red'][$i];
$ball['red'][$i] = $item;
}
}
}
$rand_blue = 0;
do{
$rand_blue = rand(1,16);
if (!in_array($rand_blue,$last_blue)){
$type = 0;
}else{
$type = 1;
}
}while($type);
$ball['blue'] = $rand_blue;
$red = implode($ball['red'],',');
print_r('红球:'.$red.' 蓝球:'.$ball['blue']);
}