简单的概率问题 设置

2017-01-09 14:17:08来源:作者:DemonLi人点击

        //修改此处请修改getPrize 中默认数据        $con = [            ['typeId' => 1, 'price' => 50],            ['typeId' => 1, 'price' => 120],            ['typeId' => 4, 'price' => 1],            ['typeId' => 4, 'price' => 2],            ['typeId' => 4, 'price' => 5],            ['typeId' => 2, 'price' => 199],        ];        $lotteryChance = [100, 0, 0, 0, 0, 100];        $total = array_sum($lotteryChance) / (1 - 0.2);        $rand = rand(0, $total - 1);        $start = 0;        for ($i = 0; $i < count($lotteryChance); $i++) {            $end = $start + $lotteryChance[$i];            try{                if ($rand >= $start && $rand < $end) {                    return $con[$i];                }            }catch(/Exception $e){                return null;            }            $start += $lotteryChance[$i];        }

 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台