当前位置:网站首页>PHP implements lottery according to probability
PHP implements lottery according to probability
2022-07-07 03:59:00 【Pointer loves me again】
One 、 Ideas
Think about how many values to fill in the array according to the possibility , for instance 30% The risk of , Just fill the array with 30 Of this prize id
Two 、 Implementation code
$data = [
[
'id' => 1,
'name' => ' Thank you for your patronage ',
'probability' => 80 // Lottery probability
],
[
'id' => 2,
'name' => '10 Yuan cash ',
'probability' => 18 // Lottery probability
],
[
'id' => 3,
'name' => '100 Yuan cash ',
'probability' => 2 // Lottery probability
],
];
$list = [];
foreach ($data as $key=>$v){
$list = array_merge($list, array_fill(0, $v['probability'], $v['id']));// Generate prize array
}
shuffle($list);// Disorder array order
$key = array_rand($list,1);// Get array random subscript
// Return the prize id, The latter can be based on the prize id Realize specific other businesses
return $list[$key];
If you have any questions, please contact me !
边栏推荐
- C# Task拓展方法
- 使用 TiDB Lightning 恢复 GCS 上的备份数据
- 你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
- Implementation of map and set
- 三重半圆环进度条,直接拿去就能用
- Operational amplifier application summary 1
- One of oscp tools: dirsearch usage Encyclopedia
- termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
- The true face of function pointer in single chip microcomputer and the operation of callback function
- Index of MySQL
猜你喜欢
Some thoughts on cross end development of kbone and applet
海思3559万能平台搭建:RTSP实时播放的支持
再AD 的 界面顶部(菜单栏)创建常用的快捷图标
Storage of data
如何检测mysql代码运行是否出现死锁+binlog查看
QT thread and other 01 concepts
Mysql-数据丢失,分析binlog日志文件
Codeworks 5 questions per day (1700 average) - day 7
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Clock in during winter vacation
随机推荐
SSL证书部署
SQL injection -day15
Gpt-3 is a peer review online when it has been submitted for its own research
API data interface of A-share index component data
List interview common questions
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
Mobile measurement and depth link platform - Branch
概率论公式
C# Task拓展方法
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Calculation of time and space complexity (notes of runners)
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
ABAP 动态内表分组循环
Ggplot facet detail adjustment summary
Redis源码学习(31),字典学习,dict.c(一)
手机号国际区号JSON格式另附PHP获取
Operational amplifier application summary 1
PIP download only, not install
Create commonly used shortcut icons at the top of the ad interface (menu bar)