红包随机分配算法
1 private void split(int sum, int count) { 2 //check sum count whether valid 3 //............. 4 5 //assgin 6 int[] splits = new int[count]; 7 Random random = new Random(); 8 int remainsCount = count - 1; 9 for (int i=0;i<count-1;i++) { 10 splits[i] = random.nextInt(sum - remainsCount)+1; 11 sum = sum-splits[i]; 12 remainsCount--; 13 } 14 splits[count-1] = sum; 15 System.out.println(Arrays.toString(splits)); 16 }