微信红包算法

#include <iostream>
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;



int main(void)
{
    int total = 10;
    int num = 8;
    int minuim = 0.01;
    
    srand (time(NULL));
    for(int i = 1; i< num; i++){
        float safe = (total - (num - i) * minuim)*1.0/(num - i);
        float money = (rand() %(int) (safe*100 - minuim* 100 ) + minuim * 100) * 1.0 / 100;
        cout << i <<" " << " money = "<< money << " res = "<< total - money <<endl;
        total -= money;
    }
    cout << 8 << " " << " money = "<< total  << " res = "<< 0 <<endl;


}

 

微信红包算法

上一篇:重磅|微信公众号交易已有官方流程 附帐号迁移流程指引


下一篇:生成微信签名