解决方案 »
- 使用"SET NAMES UTF8"后,出现乱码
- 关于APMSERV如何在服务器端设置域名解析的问题
- 跪求:php无法连接mysql的解决方法
- php伪静态的奇怪问题
- 我装好了phppgAdmin但是登录的时候不行
- 我快失去信心................希望有空的朋友帮忙
- PHP4.3.1需要提前声明变量?
- 如何在PHP登陆别人的网站并保存受密码保护的网页?(高分征答)
- ZendStudio 10 怎么支持php5.5和php5.6
- 如何强制设置Transfer-Encoding: chunked
- PHP给微信平台发送xml的问题
- 各位,这个功能怎么实现,能给个例子么,或者代码让我学习下吧!
$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);
$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);
}