如何用PHP实现抽奖概率控制?
- 内容介绍
- 文章标签
- 相关推荐
本文共计111个文字,预计阅读时间需要1分钟。
php 1, 2=> 3, 3=> 6, 4=> 9, 5=> 12, 6=> 22, 7=> 30, 8=> 50, 9=> 60, 10=> 99];echo getProbobAward($award);?>
1 => 1,
2 => 3,
3 => 6,
4 => 9,
5 => 12,
6 => 22,
7 => 30,
8 => 50,
9 => 60,
10 => 99
);
echo getProbobAward($award);
<?php defined('ROOT') or exit('Access Denied'); class Probob{ public function getProbobAward($array){ $Sum = array_sum($array); foreach($array as $key => $prob){ $Rand = mt_rand(1, $Sum); if($Rand <= $prob){ return $key; }else{ $Sum -= $prob; } } } }
本文共计111个文字,预计阅读时间需要1分钟。
php 1, 2=> 3, 3=> 6, 4=> 9, 5=> 12, 6=> 22, 7=> 30, 8=> 50, 9=> 60, 10=> 99];echo getProbobAward($award);?>
1 => 1,
2 => 3,
3 => 6,
4 => 9,
5 => 12,
6 => 22,
7 => 30,
8 => 50,
9 => 60,
10 => 99
);
echo getProbobAward($award);
<?php defined('ROOT') or exit('Access Denied'); class Probob{ public function getProbobAward($array){ $Sum = array_sum($array); foreach($array as $key => $prob){ $Rand = mt_rand(1, $Sum); if($Rand <= $prob){ return $key; }else{ $Sum -= $prob; } } } }

