微信红包算法获取若干随机数总和为固定值

public static void main(String[] args){
		double min = 0.01;
		double total = 100.0;
		int count = 20 ;

		double last = total - min*count;

		for(int i=0;i<count-1;i++){
			double avg = last/(count-i);
			double get = Math.random()*avg*2+min;
			System.out.println(get);
			last = last - get;
		}
		//last one
		System.out.println((last+min));
	}

猜你喜欢

转载自blog.csdn.net/qq779446849/article/details/52327836
今日推荐