|
|
|
@ -148,9 +148,14 @@ public class DrawLotteryService {
|
|
|
|
|
* @return 中奖者列表
|
|
|
|
|
*/
|
|
|
|
|
private List<LotteryUser> drawWinners(List<LotteryUser> list, int winnersCount) {
|
|
|
|
|
List<LotteryUser> winners = new ArrayList<>();
|
|
|
|
|
Collections.shuffle(winners, new Random());
|
|
|
|
|
return winners.subList(0, Math.min(winnersCount, winners.size()));
|
|
|
|
|
// 创建一个新列表,以便对它进行洗牌操作而不影响原始列表
|
|
|
|
|
List<LotteryUser> shuffledList = new ArrayList<>(list);
|
|
|
|
|
|
|
|
|
|
// 对新列表进行洗牌操作
|
|
|
|
|
Collections.shuffle(shuffledList, new Random());
|
|
|
|
|
|
|
|
|
|
// 返回前 winnersCount 个元素
|
|
|
|
|
return shuffledList.subList(0, Math.min(winnersCount, shuffledList.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|