大转盘php程序CI框架抽奖程序随机概率
function bingo()
{
//probability
$where = ['stock>'=>0];
$result = $this->db->order_by("probability asc")->get_where('dzp_options', $where)->result_array();
// echo $this->db->last_query();
// print_r($result);
$all_nums = .0;
$result_new = [];//新数组 [id=>[0, 10], id=>[10, 300], id=>[300, 1000]];判断中奖所属区间
$begin = 0;//上一个 all: 1,1,3,5; [0,1], [1, 2], [2, 5], [5, 10],
foreach ($result as $row)
{
$end = $begin+$row['probability'];
$result_new[$row['id']] = [$begin, $end];
$begin += $row['probability'];
$all_nums += $row['probability'];
}
$rand_nums = rand(0, $all_nums);
// echo $all_nums.'<br>';
// echo $rand_nums;
// print_r($result_new);
$bingo_id = FALSE;
foreach ($result_new as $id=

本文详细解析了使用CodeIgniter框架实现的大转盘抽奖程序,包括随机概率算法、数据库结构和PHP代码实现细节。通过调整概率值,可以精确控制不同奖项的中奖几率。
最低0.47元/天 解锁文章
143

被折叠的 条评论
为什么被折叠?



