微信红包算法思想

//总钱数

double total = 10;

//红包个数

int num = 8;

//设置最小金额

double min = 0.01;

//其他参数

double money;

double safe_total;

for(int i=1;i<num;i++){

  //注:中间用到Double.valueOf(string),String.format("%.2f",args);

  safe_total = (total-(num-i)*min)/(num-i);

  money = (Math.random()*(safe_total*100-min*100)+min*100)/100;

  total = total-money;

  //输出

}

//输出

posted @ 2016-09-19 19:55  知晓的老巢  阅读(194)  评论(0编辑  收藏  举报