做抽奖总感觉几率问题不对!
在CSDN看到一个帖子,来个测试吧!
<?php
$r=array();
for($i=0;$i<10000;$i++){
$x=rand(1,7);
$r[$i]=$x;
}
echo '<pre>';
print_r($r);
$rr=array_count_values($r);
ksort($rr);
print_r($rr);
?>
Array
(
[1] => 1426
[2] => 1404
[3] => 1411
[4] => 1412
[5] => 1410
[6] => 1440
[7] => 1497
)
Array
(
[1] => 1436
[2] => 1408
[3] => 1441
[4] => 1421
[5] => 1496
[6] => 1426
[7] => 1372
)
Array
(
[1] => 1420
[2] => 1419
[3] => 1449
[4] => 1463
[5] => 1386
[6] => 1445
[7] => 1418
)
OVER