mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Quick fix to get random shuffling.
This commit is contained in:
parent
bb8326d46b
commit
d0a570aeee
3 changed files with 8 additions and 8 deletions
|
|
@ -36,7 +36,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.filter.FilterCard;
|
||||
|
|
@ -110,7 +109,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
|
||||
@Override
|
||||
public Card getRandom(Game game) {
|
||||
if (this.size() == 0) {
|
||||
if (this.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
UUID[] cards = this.toArray(new UUID[this.size()]);
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -52,6 +52,7 @@ import mage.util.RandomUtil;
|
|||
*/
|
||||
public class Library implements Serializable {
|
||||
|
||||
private static Random rnd = new Random();
|
||||
private boolean emptyDraw;
|
||||
private final Deque<UUID> library = new ArrayDeque<>();
|
||||
private final UUID playerId;
|
||||
|
|
@ -74,7 +75,7 @@ public class Library implements Serializable {
|
|||
public void shuffle() {
|
||||
UUID[] shuffled = library.toArray(new UUID[0]);
|
||||
for (int n = shuffled.length - 1; n > 0; n--) {
|
||||
int r = RandomUtil.nextInt(n);
|
||||
int r = rnd.nextInt(n);
|
||||
UUID temp = shuffled[n];
|
||||
shuffled[n] = shuffled[r];
|
||||
shuffled[r] = temp;
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||
*/
|
||||
public class RandomUtil {
|
||||
|
||||
private static ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
private final static ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
|
||||
public static Random getRandom(){
|
||||
public static Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public static int nextInt(){
|
||||
public static int nextInt() {
|
||||
return random.nextInt();
|
||||
}
|
||||
|
||||
public static int nextInt(int max){
|
||||
public static int nextInt(int max) {
|
||||
return random.nextInt(max);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue