当前位置:网站首页>PHP wechat red packet allocation logic

PHP wechat red packet allocation logic

2022-06-12 10:20:00 Qu Shuai 369

 

/**
 * @param $total  Total money 
 * @param $n      The total number of 
 * @return array
 */
function rand_red($total,$n) {
    $arr = array();
    for ($i=$n;$i>=2;$i--) {
        $v = rand(1,(int)($total*2/$i)-1);
        $total -= $v;
        $arr[] = $v;
    }
    $arr[] = $total;
    return $arr;
}

 

原网站

版权声明
本文为[Qu Shuai 369]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010526592651.html