function run() {
$j = 1;
for ($i = 1; $i <= 50000; $i++) {
$init = rou_init();
$row = array_rand($init, 1);
$last = isset($that) ? $that : 'start';
$that = $row % 2;
if ($last === $that || $row == 0) {
$j++;
} else {
$res['all-times'][$j]++;
if ($j == 9) {
if (isset($k) && $k != $i) {
var_dump($i, $k);
$res['all-times'][$j . 'times'][] = $i - $k;
}
$k = $i;
}
$j = 1;
}
if ($that == 1) {
$res['odd'] += 1;
} else {
$res['even'] += 1;
}
}
ksort($res['all-times']);
return $res;
}
?>
array 'all-times' => array 1 => int 12478 2 => int 5602 3 => int 3055 4 => int 1868 5 => int 764 6 => int 509 7 => int 85 8 => int 85 9 => int 170 'odd' => int 23681 'even' => int 26319
var_dump($i, $k);
出来的虽然每次都不一样
$res['all-times'][$j . 'times'][] = $i - $k;
但是 $i - $k 都是固定的几个数字
看来得研究php源码的随机算法
改了下方法,现在随机基本上OK
回复删除但是原因还是没找出来
function roulette_run() {
$resArr = array();
for ($ii = 0; $ii <= 10000; $ii++) {
$init = roulette_init();
$num = array_rand($init, 1);
$resArr[] = $num;
}
shuffle($resArr);
$j = 1;
for ($i = 1; $i <= count($resArr); $i++) {
$row = $resArr[$i];
//echo $row."\n";
$last = isset($that) ? $that : 'start';
$that = $row % 2;
//echo $that."\n";
if ($last === $that || $row == 0) {
$j++;
} else {
$res['all-times'][$j]++;
if ($j > 7) {
if (isset($k) && $k != $i) {
$res['all-times'][$j . 'times'][] = $i - $k;
}
$k = $i;
}
$j = 1;
}
if ($that == 1) {
$res['odd'] += 1;
} else {
$res['even'] += 1;
}
}
//var_dump(array_sum($res['all-times']));
ksort($res['all-times']);
return $res;
}