指定红包金额,最小红包金额和红包个数就可以自动生成
[PHP]代码
<?php $total=20;//红包总金额 $num=10;// 分成10个红包,支持10人随机领取 $min=0.01;//每个人最少能收到0.01元 $redpack = new redpack($total,$num,$min); $jieguo = $redpack->getPack(); foreach($jieguo as $key=>$val){ $n = $key+1; echo '第'.$n.'个红包:'.$val['money'].' 元,余额:'.$val['balance'].' 元<br>'; } class redpack{ //总金额 private $total=0; //红包数量 private $num=0; //最小红包金额 private $min=0.01; public function __construct($total,$num,$min) { $this->total = $total; $this->num = $num; $this->min = $min; } //红包结果 public function getPack() { $total = $this->total; $num = $this->num; $min = $this->min; 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; //红包数据 $readPack[]= [ 'money'=>$money, 'balance'=>$total, ]; } //最后一个红包,不用随机 $readPack[] = [ 'money'=>$money, 'balance'=>0, ]; //返回结果 return $readPack; } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
