当前位置:网站首页>PHP 实现根据概率抽奖
PHP 实现根据概率抽奖
2022-07-06 21:17:00 【指针再爱我一次】
一、思路
大概思路根据可能性向数组中填写多少个值,比如说30%的几率,就向数组中填入30个这个奖品的id
二、实现代码
$data = [
[
'id' => 1,
'name' => '谢谢惠顾',
'probability' => 80 // 抽奖概率
],
[
'id' => 2,
'name' => '10元现金',
'probability' => 18 // 抽奖概率
],
[
'id' => 3,
'name' => '100元现金',
'probability' => 2 // 抽奖概率
],
];
$list = [];
foreach ($data as $key=>$v){
$list = array_merge($list, array_fill(0, $v['probability'], $v['id']));//生成奖品数组
}
shuffle($list);//打乱数组顺序
$key = array_rand($list,1);//获取数组随机下标
// 返回奖品id, 后面可以根据奖品id实现具体其他业务
return $list[$key];
有问题欢迎联系我哦!
边栏推荐
- [safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
- 自适应非欧表征广告检索系统AMCAD
- 10 ways of interface data security assurance
- Arduino droplet detection
- 三重半圆环进度条,直接拿去就能用
- HW-小记(二)
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- Search of linear table
- 小程序能运行在自有App中,且实现直播和连麦?
猜你喜欢

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式

tflite模型转换和量化

SQL injection -day15
![[MySQL] row sorting in MySQL](/img/97/8a451fa62796838e11242c86eecd8d.png)
[MySQL] row sorting in MySQL

Calculation of time and space complexity (notes of runners)

Set WiFi automatic connection for raspberry pie

一些常用软件相关

【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001

About Tolerance Intervals
10 ways of interface data security assurance
随机推荐
Force buckle ----- path sum III
The true face of function pointer in single chip microcomputer and the operation of callback function
Restcloud ETL Community Edition June featured Q & A
使用 BR 备份 TiDB 集群到 GCS
力扣------路径总和 III
接口数据安全保证的10种方式
再AD 的 界面顶部(菜单栏)创建常用的快捷图标
Hongmi K40S root gameplay notes
Flutter3.0, the applet is not only run across mobile applications
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
qt-线程等01概念
Redis configuration and optimization of NoSQL
Que savez - vous de la sérialisation et de l'anti - séquence?
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
Preprocessing - interpolation
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Probability formula