微信紅包算法獲取若干隨機數總和爲固定值

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));
	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章