当前位置:网站首页>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 !
边栏推荐
- 浅谈网络安全之文件上传
- VHDL implementation of single cycle CPU design
- termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
- R data analysis: how to predict Cox model and reproduce high score articles
- Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
- Create commonly used shortcut icons at the top of the ad interface (menu bar)
- 22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
- QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)
- One of oscp tools: dirsearch usage Encyclopedia
- ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
猜你喜欢

【安全攻防】序列化與反序列,你了解多少?

Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND

Class常量池与运行时常量池

史上最全学习率调整策略lr_scheduler
![[MySQL] row sorting in MySQL](/img/97/8a451fa62796838e11242c86eecd8d.png)
[MySQL] row sorting in MySQL

Storage of data

Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications

Introduction to opensea platform developed by NFT trading platform (I)

卡尔曼滤波-1

力扣------路径总和 III
随机推荐
SQL injection -day15
【mysql】mysql中行排序
本机mysql
机械臂速成小指南(十):可达工作空间
红米k40s root玩机笔记
Implementation steps of docker deploying mysql8
QT opens a file and uses QFileDialog to obtain the file name, content, etc
接口数据安全保证的10种方式
Some common software related
Create commonly used shortcut icons at the top of the ad interface (menu bar)
The true face of function pointer in single chip microcomputer and the operation of callback function
Codeworks 5 questions per day (1700 average) - day 7
golang 根据生日计算星座和属相
Redis源码学习(31),字典学习,dict.c(一)
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
R data analysis: how to predict Cox model and reproduce high score articles
Enter the rough outline of the URL question (continuously updated)