mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Fixes inefficient shuffle algorithm.
Note that shuffling 13 times in a row is not necessary. Collections.shuffle will produce every possible shuffle with equal probability already.
This commit is contained in:
@@ -1608,26 +1608,8 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
return;
|
||||
}
|
||||
|
||||
// overdone but wanted to make sure it was really random
|
||||
final Random random = MyRandom.getRandom();
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
|
||||
int s = list.size();
|
||||
for (int i = 0; i < s; i++) {
|
||||
list.add(random.nextInt(s - 1), list.remove(random.nextInt(s)));
|
||||
}
|
||||
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
Collections.shuffle(list, random);
|
||||
// Note: Shuffling once is sufficient.
|
||||
Collections.shuffle(list, MyRandom.getRandom());
|
||||
|
||||
getZone(ZoneType.Library).setCards(getController().cheatShuffle(list));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user