当前位置:网站首页>PHP wechat red packet grabbing algorithm
PHP wechat red packet grabbing algorithm
2022-07-03 07:45:00 【. Zhou Zhou】
php Wechat red packet algorithm
function qiangHongbao() {
$total=10;// Total
$num=8;// Divide into 8 Red envelopes , Support 8 People receive at random
$min=0.01;// Everyone can at least receive 0.01 element
for ($i=1;$i<$num;$i++) {
$safe_total=($total-($num-$i)*$min)/($num-$i);// Random safety upper limit
$money=mt_rand($min*100,$safe_total*100)/100;
$total=$total-$money;
echo ' The first '.$i.' Red envelopes :'.$money.' element , balance :'.$total.' element <br/>';
}
echo ' The first '.$num.' Red envelopes :'.$total.' element , balance :0 element ';
}
// Output results
// The first 1 Red envelopes :0.08 element , balance :9.92 element
// The first 2 Red envelopes :0.82 element , balance :9.1 element
// The first 3 Red envelopes :1.4 element , balance :7.7 element
// The first 4 Red envelopes :0.87 element , balance :6.83 element
// The first 5 Red envelopes :1.07 element , balance :5.76 element
// The first 6 Red envelopes :2.47 element , balance :3.29 element
// The first 7 Red envelopes :1.01 element , balance :2.28 element
// The first 8 Red envelopes :2.28 element , balance :0 element
边栏推荐
- 技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
- PAT甲级 1030 Travel Plan
- Vertx's responsive redis client
- tp3.2和tp5.0的区别
- Reconnaissance et détection d'images - Notes
- Pgadmin 4 v6.11 release, PostgreSQL open source graphical management tool
- 【LeetCode】2. Valid Parentheses·有效的括号
- Go language foundation ----- 16 ----- goroutine, GPM model
- HarmonyOS第三次培训笔记
- Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
猜你喜欢
技术干货|昇思MindSpore算子并行+异构并行,使能32卡训练2420亿参数模型
【LeetCode】3. Merge Two Sorted Lists·合并两个有序链表
【LeetCode】2. Valid Parentheses·有效的括号
Analysis of the problems of the 7th Blue Bridge Cup single chip microcomputer provincial competition
【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
HCIA notes
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Pat class a 1032 sharing
随机推荐
Robots protocol
什么是定义?什么是声明?它们有何区别?
PAT甲级 1031 Hello World for U
Go language foundation ------ 14 ------ gotest
Epoll related references
The babbage industrial policy forum
【LeetCode】3. Merge two sorted lists · merge two ordered linked lists
Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18
go语言-循环语句
Segment read
Pat grade a 1029 median
Image recognition and detection -- Notes
Vertx's responsive MySQL template
Go language foundation ----- 02 ----- basic data types and operators
Go language foundation ----- 13 ----- file
Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
华为交换机基础配置(telnet/ssh登录)
[mindspire paper presentation] summary of training skills in AAAI long tail problem