当前位置:网站首页>PHP微信抢红包的算法
PHP微信抢红包的算法
2022-07-03 07:41:00 【.周周】
php微信红包算法
function qiangHongbao() {
$total=10;//总额
$num=8;// 分成8个红包,支持8人随机领取
$min=0.01;//每个人最少能收到0.01元
for ($i=1;$i<$num;$i++) {
$safe_total=($total-($num-$i)*$min)/($num-$i);//随机安全上限
$money=mt_rand($min*100,$safe_total*100)/100;
$total=$total-$money;
echo '第'.$i.'个红包:'.$money.' 元,余额:'.$total.' 元 <br/>';
}
echo '第'.$num.'个红包:'.$total.' 元,余额:0 元';
}
// 输出结果
// 第1个红包:0.08 元,余额:9.92 元
// 第2个红包:0.82 元,余额:9.1 元
// 第3个红包:1.4 元,余额:7.7 元
// 第4个红包:0.87 元,余额:6.83 元
// 第5个红包:1.07 元,余额:5.76 元
// 第6个红包:2.47 元,余额:3.29 元
// 第7个红包:1.01 元,余额:2.28 元
// 第8个红包:2.28 元,余额:0 元边栏推荐
- HarmonyOS第三次培训笔记
- IndexSort
- Go language foundation ------ 12 ------ JSON
- Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
- 【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
- Responsive MySQL of vertx
- Lucene introduces NFA
- Go language foundation ----- 15 ----- reflection
- yarn link 是如何帮助开发者对 NPM 包进行 debug 的?
- experiment.........
猜你喜欢

Usage of requests module

技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估

Common architectures of IO streams

Technical dry goods Shengsi mindspire operator parallel + heterogeneous parallel, enabling 32 card training 242 billion parameter model

IO stream system and FileReader, filewriter

PAT甲级 1032 Sharing

Various postures of CS without online line

技术干货|关于AI Architecture未来的一些思考

OSPF experiment

不出网上线CS的各种姿势
随机推荐
IndexSort
昇思MindSpore再升级,深度科学计算的极致创新
HarmonyOS第三次培训笔记
Why is data service the direction of the next generation data center?
Common methods of file class
【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
HCIA notes
The babbage industrial policy forum
Go language foundation ----- 11 ----- regular expression
PAT甲级 1032 Sharing
TypeScript let与var的区别
Vertx multi vertical shared data
Lombok cooperates with @slf4j and logback to realize logging
Go language foundation ----- 13 ----- file
Enter three times and guess a number
FileInputStream and fileoutputstream
SQL create temporary table
Some basic operations of reflection
EtherCAT state machine transition (ESM)