Home > php教程 > PHP源码 > php随机概率红包算法

php随机概率红包算法

PHP中文网
Release: 2016-05-23 08:39:04
Original
1578 people have browsed it


 /**
     * @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;

    }
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template