当前位置:网站首页>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 !
边栏推荐
- 【安全攻防】序列化与反序列,你了解多少?
- One of oscp tools: dirsearch usage Encyclopedia
- The true face of function pointer in single chip microcomputer and the operation of callback function
- 力扣------路径总和 III
- Class constant pool and runtime constant pool
- 什么是 BA ?BA怎么样?BA和BI是什么关系?
- Redis源码学习(30),字典学习,dict.h
- 使用 BR 恢复 GCS 上的备份数据
- PHP lightweight Movie Video Search Player source code
- 21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
猜你喜欢
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
web服务性能监控方案
运算放大器应用汇总1
【安全攻防】序列化与反序列,你了解多少?
Web service performance monitoring scheme
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
Class常量池与运行时常量池
Summer 2022 daily question 1 (1)
[development software] tilipa Developer Software
随机推荐
一些常用软件相关
Clock in during winter vacation
MySQL的索引
力扣------路径总和 III
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
Search of linear table
NoSQL之Redis配置与优化
ABAP dynamic inner table grouping cycle
Enter the rough outline of the URL question (continuously updated)
qt-线程等01概念
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
概率论公式
数据的存储
太方便了,钉钉上就可完成代码发布审批啦!
【knife-4j 快速搭建swagger】
. Net interface can be implemented by default
Kalman filter-1
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
[hcie TAC] question 3
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议