Skip to content

Instantly share code, notes, and snippets.

@techom
Created March 8, 2016 06:43
Show Gist options
  • Select an option

  • Save techom/7622b85c6281e78a13a0 to your computer and use it in GitHub Desktop.

Select an option

Save techom/7622b85c6281e78a13a0 to your computer and use it in GitHub Desktop.

Revisions

  1. techom created this gist Mar 8, 2016.
    16 changes: 16 additions & 0 deletions weixin.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    header("Content-Type: text/html;charset=utf-8");
    $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 元';