当前位置:网站首页>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 !
边栏推荐
- Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
- SQL injection -day15
- On file uploading of network security
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- Redis configuration and optimization of NoSQL
- It's too convenient. You can complete the code release and approval by nailing it!
- 海思3559万能平台搭建:RTSP实时播放的支持
- 【开发软件】 tilipa开发者软件
- What is the experience of maintaining Wanxing open source vector database
- 【编码字体系列】OpenDyslexic字体
猜你喜欢
Some thoughts on cross end development of kbone and applet
tflite模型转换和量化
10 ways of interface data security assurance
ABAP dynamic inner table grouping cycle
[security attack and Defense] how much do you know about serialization and deserialization?
Mysql-数据丢失,分析binlog日志文件
VHDL implementation of arbitrary size matrix multiplication
Introduction to opensea platform developed by NFT trading platform (I)
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Hisilicon 3559 universal platform construction: RTSP real-time playback support
随机推荐
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
UltraEdit-32 温馨提示:右协会,取消 bak文件[通俗易懂]
[leetcode] 700 and 701 (search and insert of binary search tree)
Native MySQL
Class constant pool and runtime constant pool
一些常用软件相关
使用 Dumpling 备份 TiDB 集群数据到 GCS
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Redis源码学习(30),字典学习,dict.h
VHDL implementation of arbitrary size matrix multiplication
First understand the principle of network
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
PIP download only, not install
What is Ba? How about Ba? What is the relationship between Ba and Bi?
MySQL的索引
Implementation of binary search tree
Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
Delete data in SQL
Redis configuration and optimization of NoSQL