当前位置:网站首页>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];
有问题欢迎联系我哦!
边栏推荐
- 一些常用软件相关
- Set static IP for raspberry pie
- ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
- R data analysis: how to predict Cox model and reproduce high score articles
- 数据的存储
- Set WiFi automatic connection for raspberry pie
- 19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
- ubuntu20安裝redisjson記錄
- How to customize the shortcut key for latex to stop running
- The most complete learning rate adjustment strategy in history LR_ scheduler
猜你喜欢

VHDL implementation of arbitrary size matrix addition operation

Basic concepts of Huffman tree
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/1c/e5ae74e65bacf688d7f61cc1b71d3e.png)
[security attack and Defense] how much do you know about serialization and deserialization?

Ubuntu20 installation redisjson record

Ubuntu 20 installation des enregistrements redisjson

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

Summer 2022 daily question 1 (1)

On file uploading of network security

Redis configuration and optimization of NoSQL
Implementation steps of docker deploying mysql8
随机推荐
Antd Comment 递归循环评论
使用 BR 恢复 GCS 上的备份数据
map和set的实现
VHDL implementation of single cycle CPU design
R data analysis: how to predict Cox model and reproduce high score articles
Set WiFi automatic connection for raspberry pie
24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
Delete data in SQL
Enumeration general interface & enumeration usage specification
QT opens a file and uses QFileDialog to obtain the file name, content, etc
SQL injection -day15
Docker部署Mysql8的实现步骤
数据的存储
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
cuda编程
Tflite model transformation and quantification
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
Allow public connections to local Ruby on Rails Development Server
如何检测mysql代码运行是否出现死锁+binlog查看