时间:2021-07-01 10:21:17 帮助过:6人阅读
$a = array(1,2,3,4);
$b = array_merge($a, $a, $a, $a, $a);
for($i=0; $i<1000; $i++) {
shuffle($b);
if(! preg_match('/(.)\1/', join('', $b))) printf("%d %s\n", $i, join('', $b));
}
$a=array();
function check(){
global $a;
$count=count($a)-1;
if ($count >= 1 && $a[$count] == $a[$count-1]) {
$a[$count]=mt_rand(1,4);
check();
}
}
for ($i=0; $i < 20; $i++) {
$a[$i]=mt_rand(1,4);
check();
echo $a[$i]."
";
}
?>