/** * @param $num * @param $total * @param int $range 差距是否大 * @return array|int */ private function randomSplit($num,$total,$range=1){ if($num<2){ return $total; } $p=array(); $min=floor($total/$num-$range); $max=floor($total/$num+$range); for($i=0;$i<$num-1;$i++){ $depart=mt_rand($min,$max); $p[]=$depart; $total-=$depart; } $p[]=$total; return $p; }