解决方案 »

  1.   

    这样可能好点$people = 3;    //人数
    $percent = 100; //百分比
    $res = array_fill(0, 3, floor($percent/$people)); //平均分配
    $d = 5; //容差
    foreach($res as &$v) $v += rand(-$d, $d);
    $res[rand(0, $people-1)] += $percent - array_sum($res); //随机将残差补入
    print_r($res);
      

  2.   

    忘记上来结贴了,感谢版主大大的回复,问题已经解决了,贴出来与大家分享:public static function rand_bouns($person){ //百分比
    $percent = 100; $now_person = $person; $bouns = array(); for($i=0;$i<=$person-1;$i++){
    $bouns[$i] = self::get_bouns($now_person,$percent);
    $percent = $percent - $bouns[$i];
    $now_person = $now_person - 1;
    $now_bouns += $bouns[$i]; } return $bouns;

    }
    public static function get_bouns($person,$percent){
    if($person==1) return $percent;
    $max = 30;
    if($percent < $max)  $max = $percent; $min = $percent-$max*($person-1) <= 0 ? 1 : $percent-$max*($person-1);
    $max = $max-($person) <= 0 ? 1 : $max-($person); return rand($min,$max);
    }