当前位置:网站首页>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 !
边栏推荐
- 如何检测mysql代码运行是否出现死锁+binlog查看
- . Net interface can be implemented by default
- The JSON format of the international area code of the mobile phone number is obtained with PHP
- Mobile measurement and depth link platform - Branch
- Kalman filter-1
- Force buckle ----- path sum III
- Clock in during winter vacation
- Simple implementation of AVL tree insertion and verification operations
- .net中 接口可以有默认实现了
- 机械臂速成小指南(十):可达工作空间
猜你喜欢
Mysql-数据丢失,分析binlog日志文件
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
Kotlin Android environment construction
Search of linear table
Some common software related
[leetcode] 700 and 701 (search and insert of binary search tree)
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
史上最全学习率调整策略lr_scheduler
Mobile measurement and depth link platform - Branch
随机推荐
接口数据安全保证的10种方式
Kotlin Android environment construction
VHDL implementation of arbitrary size matrix multiplication
自适应非欧表征广告检索系统AMCAD
Que savez - vous de la sérialisation et de l'anti - séquence?
运算放大器应用汇总1
Adaptive non European advertising retrieval system amcad
一些常用软件相关
使用切面实现记录操作日志
Web service performance monitoring scheme
三重半圆环进度条,直接拿去就能用
什么是 BA ?BA怎么样?BA和BI是什么关系?
ggplot 分面的细节调整汇总
红米k40s root玩机笔记
Create commonly used shortcut icons at the top of the ad interface (menu bar)
VHDL implementation of single cycle CPU design
机器学习笔记 - 使用机器学习进行鸟类物种分类
PHP lightweight Movie Video Search Player source code
Class常量池与运行时常量池
. Net interface can be implemented by default