当前位置:网站首页>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 !
边栏推荐
- QT 打开文件 使用 QFileDialog 获取文件名称、内容等
- 使用 TiDB Lightning 恢复 GCS 上的备份数据
- Arduino droplet detection
- QT thread and other 01 concepts
- 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
- 本机mysql
- HW notes (II)
- map和set的实现
- 【编码字体系列】OpenDyslexic字体
- 浅谈网络安全之文件上传
猜你喜欢
力扣------路径总和 III
浅谈网络安全之文件上传
【系统管理】清理任务栏的已删除程序的图标缓存
Create commonly used shortcut icons at the top of the ad interface (menu bar)
QT thread and other 01 concepts
qt-线程等01概念
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
VHDL implementation of single cycle CPU design
ggplot 分面的细节调整汇总
Some thoughts on cross end development of kbone and applet
随机推荐
map和set的实现
[leetcode] 700 and 701 (search and insert of binary search tree)
Web service performance monitoring scheme
Kotlin Android environment construction
opencv第三方库
Mysql-数据丢失,分析binlog日志文件
PHP lightweight Movie Video Search Player source code
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
链表面试常见题
海思3559万能平台搭建:RTSP实时播放的支持
API data interface of A-share index component data
tflite模型转换和量化
Simple implementation of AVL tree insertion and verification operations
UltraEdit-32 温馨提示:右协会,取消 bak文件[通俗易懂]
qt-线程等01概念
【编码字体系列】OpenDyslexic字体
Search of linear table
Operational amplifier application summary 1
OSCP工具之一: dirsearch用法大全
Implementation steps of docker deploying mysql8