package test;
import java.math.BigDecimal;
import java.util.Random;
public class Test{
public static void main(String[] args) {
double total=10;//总金额
int num=6;//随机红包数
double min=0.01;//红包最小额度
for (int i=0;i<num-1;i++){
double sa_tolat=(total-(num-1-i)*min)/(num-1-i);
BigDecimal a = new BigDecimal(sa_tolat);
double x = a.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
Random rd = new Random();
double sum_money = (min+rd.nextDouble()) * x;
BigDecimal b = new BigDecimal(sum_money);
double y = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
BigDecimal c = new BigDecimal(Double.toString(total));
BigDecimal d = new BigDecimal(Double.toString(y));
total= c.subtract(d).doubleValue();
System.out.println("第"+(i+1)+"个红包金额=="+y+"余额=="+total);
}
//最后一个红包的金额
System.out.println("第"+num+"个红包金额=="+total+"余额=="+0.00);
}
}