时间:2021-07-01 10:21:17 帮助过:13人阅读
function distribute($total, $num) {
$avg = $total / $num;
$r = array_fill(0, $num, $avg);
for($i=0; $i<$num; $i+=2) {
$t = rand(1, $avg * 100) / 100;
$r[$i] -= $t;
if($r[$i] <= 0) $r[$i] = 0.01;
$r[$i+1] += $t;
}
$r[$num-1] = $total - array_sum(array_slice($r, 0, -1));
return $r;
}