您的位置:首页 > 移动开发 > 微信开发

模仿微信红包

2016-03-21 14:52 447 查看
/*

* 红包算法 最小值0.01元 最大值 200

* $total 红包总数

* $number 红包个数

*/

public function get_test($total, $number)

{

if ($total > 200) {

return "最大值不能超过200元";

} else {

$total = $total * 100;

$list = new ArrayList();

$tal = $total;

$total_array = array();

for ($i = 1; $i <= $number; $i ++) {

if ($i == $number) {

$temp = $tal;

} else {

$temp = rand(1, $tal - 1 * ($number - $i));//控制没次发红包至少一分钱

}

$total_array = array_merge($total_array, array(

$i => $temp / 100

));

$tal = $tal - $temp;

}

}

return $total_array;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: