diff --git a/Mage.Client/src/main/java/mage/client/deck/generator/DeckGenerator.java b/Mage.Client/src/main/java/mage/client/deck/generator/DeckGenerator.java index d2b959c1c7..97471ed50b 100644 --- a/Mage.Client/src/main/java/mage/client/deck/generator/DeckGenerator.java +++ b/Mage.Client/src/main/java/mage/client/deck/generator/DeckGenerator.java @@ -44,6 +44,7 @@ import mage.client.util.sets.ConstructedFormats; import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Rarity; +import mage.util.RandomUtil; import mage.util.TournamentUtil; /** @@ -120,7 +121,6 @@ public class DeckGenerator { */ private static String getRandomColors(String selectedColors) { - Random random = new Random(); List availableColors = new ArrayList<>(); for (ColoredManaSymbol cms : ColoredManaSymbol.values()) { availableColors.add(cms.toString().charAt(0)); @@ -138,7 +138,7 @@ public class DeckGenerator { } } for (int i = 0; i < randomColors && !availableColors.isEmpty(); i++) { - int index = random.nextInt(availableColors.size()); + int index = RandomUtil.nextInt(availableColors.size()); generatedColors.append(availableColors.remove(index)); } return generatedColors.toString(); @@ -214,14 +214,13 @@ public class DeckGenerator { List cardPool = CardRepository.instance.findCards(criteria); int retrievedCount = cardPool.size(); List deckCMCs = genPool.getCMCsForSpellCount(spellCount); - Random random = new Random(); int count = 0; int reservesAdded = 0; boolean added; if (retrievedCount > 0 && retrievedCount >= spellCount) { int tries = 0; while (count < spellCount) { - Card card = cardPool.get(random.nextInt(retrievedCount)).getMockCard(); + Card card = cardPool.get(RandomUtil.nextInt(retrievedCount)).getMockCard(); if (genPool.isValidSpellCard(card)) { int cardCMC = card.getManaCost().convertedManaCost(); for (DeckGeneratorCMC.CMC deckCMC : deckCMCs) { @@ -278,10 +277,9 @@ public class DeckGenerator { if (!genPool.isMonoColoredDeck() && genDialog.useNonBasicLand()) { List landCards = genPool.filterLands(CardRepository.instance.findCards(criteria)); int allCount = landCards.size(); - Random random = new Random(); if (allCount > 0) { while (countNonBasic < landsCount / 2) { - Card card = landCards.get(random.nextInt(allCount)); + Card card = landCards.get(RandomUtil.nextInt(allCount)); if (genPool.isValidLandCard(card)) { Card addedCard = card.copy(); deckLands.add(addedCard); @@ -394,10 +392,9 @@ public class DeckGenerator { * @return a single basic land that produces the color needed. */ private static Card getBasicLand(ColoredManaSymbol color, Map> basicLands) { - Random random = new Random(); String landName = DeckGeneratorPool.getBasicLandName(color.toString()); List basicLandsInfo = basicLands.get(landName); - return basicLandsInfo.get(random.nextInt(basicLandsInfo.size() - 1)).getMockCard().copy(); + return basicLandsInfo.get(RandomUtil.nextInt(basicLandsInfo.size() - 1)).getMockCard().copy(); } } diff --git a/Mage.Client/src/main/java/mage/client/deck/generator/DeckGeneratorPool.java b/Mage.Client/src/main/java/mage/client/deck/generator/DeckGeneratorPool.java index 7c7ff556f1..b5dcd45edf 100644 --- a/Mage.Client/src/main/java/mage/client/deck/generator/DeckGeneratorPool.java +++ b/Mage.Client/src/main/java/mage/client/deck/generator/DeckGeneratorPool.java @@ -32,6 +32,7 @@ import mage.cards.Card; import mage.cards.decks.Deck; import mage.cards.repository.CardInfo; import mage.constants.ColoredManaSymbol; +import mage.util.RandomUtil; import java.util.*; @@ -390,7 +391,6 @@ public class DeckGeneratorPool */ private List getFixedSpells() { - Random random = new Random(); int spellSize = deckCards.size(); int nonLandSize = (deckSize - landCount); @@ -409,7 +409,7 @@ public class DeckGeneratorPool spellsToAdd.add(reserveSpells.get(i)); for (int i = spellsNeeded + 1; i < reserveSpells.size() - 1; i++) { - int j = random.nextInt(i); + int j = RandomUtil.nextInt(i); Card randomCard = reserveSpells.get(j); if (isValidSpellCard(randomCard) && j < spellsToAdd.size()) { spellsToAdd.set(j, randomCard); @@ -424,7 +424,7 @@ public class DeckGeneratorPool else if(spellSize > (deckSize - landCount)) { int spellsRemoved = (spellSize)-(deckSize-landCount); for(int i = 0; i < spellsRemoved; ++i) { - deckCards.remove(random.nextInt(deckCards.size())); + deckCards.remove(RandomUtil.nextInt(deckCards.size())); } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java b/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java index 9b25eea371..5748b13cd4 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java @@ -46,6 +46,7 @@ import mage.cards.repository.ExpansionRepository; import mage.client.MageFrame; import mage.client.constants.Constants.DeckEditorMode; import mage.constants.Rarity; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -118,7 +119,6 @@ public class AddLandDialog extends MageDialog { } private void addLands(String landName, int number) { - Random random = new Random(); String landSetName = (String) cbLandSet.getSelectedItem(); CardCriteria criteria = new CardCriteria(); @@ -142,7 +142,7 @@ public class AddLandDialog extends MageDialog { } for (int i = 0; i < number; i++) { - Card land = cards.get(random.nextInt(cards.size())).getMockCard(); + Card land = cards.get(RandomUtil.nextInt(cards.size())).getMockCard(); deck.getCards().add(land); } } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java index 2a4a1ca9f4..3b6dccae02 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java @@ -51,6 +51,7 @@ import mage.client.constants.Constants; import mage.client.dialog.PreferencesDialog; import mage.client.util.sets.ConstructedFormats; import mage.remote.Connection; +import mage.util.RandomUtil; import net.java.truevfs.access.TFile; import net.java.truevfs.access.TFileOutputStream; import net.java.truevfs.access.TVFS; @@ -68,7 +69,6 @@ import org.mage.plugins.card.utils.CardImageUtils; public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable { private static final Logger logger = Logger.getLogger(DownloadPictures.class); - private static final Random rnd = new Random(); private JProgressBar bar; private final JOptionPane dlg; @@ -689,7 +689,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab private void setUpConnection(URLConnection httpConn) { // images download from magiccards.info may not work with default 'User-Agent: Java/1.x.x' request header - switch (rnd.nextInt(3)) { + switch (RandomUtil.nextInt(3)) { // chrome case 0: httpConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); diff --git a/Mage.Common/src/mage/utils/DeckBuilder.java b/Mage.Common/src/mage/utils/DeckBuilder.java index 025a73bd37..525049b4fd 100644 --- a/Mage.Common/src/mage/utils/DeckBuilder.java +++ b/Mage.Common/src/mage/utils/DeckBuilder.java @@ -14,6 +14,7 @@ import mage.cards.decks.Deck; import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.interfaces.rate.RateCallback; +import mage.util.RandomUtil; /** * Builds deck from provided card pool. @@ -205,7 +206,7 @@ public class DeckBuilder { ColoredManaSymbol bestColor = null; //Default to a color in the allowed colors if (allowedColors != null && !allowedColors.isEmpty()) { - bestColor = allowedColors.get(new Random().nextInt(allowedColors.size())); + bestColor = allowedColors.get(RandomUtil.nextInt(allowedColors.size())); } int lowestRatio = Integer.MAX_VALUE; for (final ColoredManaSymbol color : ColoredManaSymbol.values()) { diff --git a/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java b/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java index 9d37e749ad..b2dc9b0b79 100644 --- a/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java +++ b/Mage.Server.Plugins/Mage.Game.MomirDuel/src/mage/game/MomirDuel.java @@ -56,6 +56,7 @@ import mage.game.permanent.token.EmptyToken; import mage.game.turn.TurnMod; import mage.players.Player; import mage.util.CardUtil; +import mage.util.RandomUtil; /** * @@ -135,7 +136,6 @@ class MomirEmblem extends Emblem { class MomirEffect extends OneShotEffect { - private static final Random rnd = new Random(); public MomirEffect() { super(Outcome.PutCreatureInPlay); @@ -158,7 +158,7 @@ class MomirEffect extends OneShotEffect { CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).convertedManaCost(value); List options = CardRepository.instance.findCards(criteria); if (options != null && !options.isEmpty()) { - Card card = options.get(rnd.nextInt(options.size())).getCard(); + Card card = options.get(RandomUtil.nextInt(options.size())).getCard(); EmptyToken token = new EmptyToken(); CardUtil.copyTo(token).from(card); token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), false, false); diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java index e816a8757d..39b0266060 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java @@ -104,6 +104,7 @@ import mage.players.Player; import mage.target.Target; import mage.target.TargetCard; import mage.target.Targets; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -128,7 +129,6 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ { protected Set actionCache; private static final List optimizers = new ArrayList<>(); protected int lastLoggedTurn = 0; - Random random = new Random(); protected static final String BLANKS = "..............................................."; static { @@ -631,7 +631,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ { if (depth == maxDepth && action instanceof PassAbility) { val = val - PASSIVITY_PENALTY; // passivity penalty } - if (val > alpha || (depth == maxDepth && val == alpha && random.nextBoolean())) { // Adding random for equal value to get change sometimes + if (val > alpha || (depth == maxDepth && val == alpha && RandomUtil.nextBoolean())) { // Adding random for equal value to get change sometimes alpha = val; bestNode = newNode; bestNode.setScore(val); diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 6264e60301..2bcae9b1ff 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -138,10 +138,7 @@ import mage.target.common.TargetDiscard; import mage.target.common.TargetOpponent; import mage.target.common.TargetPermanentOrPlayer; import mage.target.common.TargetSpellOrPermanent; -import mage.util.Copier; -import mage.util.MessageToClient; -import mage.util.TournamentUtil; -import mage.util.TreeNode; +import mage.util.*; import org.apache.log4j.Logger; /** @@ -165,7 +162,6 @@ public class ComputerPlayer extends PlayerImpl implements Player { private transient List chosenColors; private transient ManaCost currentUnpaidMana; - private final Random random = new Random(); public ComputerPlayer(String name, RangeOfInfluence range) { super(name, range); @@ -1258,7 +1254,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variablCost) { log.debug("announceXMana"); //TODO: improve this - int value = new Random().nextInt(max + 1); + int value = RandomUtil.nextInt(max + 1); if (value < max) { value++; } @@ -1558,7 +1554,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { } //TODO: improve this if (min < max && min == 0) { - return new Random().nextInt(max + 1); + return RandomUtil.nextInt(max + 1); } return min; } @@ -1587,7 +1583,6 @@ public class ComputerPlayer extends PlayerImpl implements Player { } private static void addBasicLands(Deck deck, String landName, int number) { - Random random = new Random(); Set landSets = TournamentUtil.getLandSetCodeForDeckSets(deck.getExpansionSetCodes()); CardCriteria criteria = new CardCriteria(); @@ -1605,7 +1600,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { } for (int i = 0; i < number; i++) { - Card land = cards.get(random.nextInt(cards.size())).getCard(); + Card land = cards.get(RandomUtil.nextInt(cards.size())).getCard(); deck.getCards().add(land); } } @@ -2239,7 +2234,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { UUID randomOpponentId = game.getOpponents(abilityControllerId).iterator().next(); Set opponents = game.getOpponents(abilityControllerId); if (opponents.size() > 1) { - int rand = random.nextInt(opponents.size()); + int rand = RandomUtil.nextInt(opponents.size()); int count = 0; for (UUID currentId : opponents) { if (count == rand) { diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java index 60212a9ee1..8a315878f1 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java @@ -54,6 +54,7 @@ import mage.players.Player; import mage.target.Target; import mage.target.TargetAmount; import mage.target.TargetCard; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -65,7 +66,6 @@ import org.apache.log4j.Logger; public class SimulatedPlayerMCTS extends MCTSPlayer { private boolean isSimulatedPlayer; - private static Random rnd = new Random(); private int actionCount = 0; private static final Logger logger = Logger.getLogger(SimulatedPlayerMCTS.class); @@ -115,21 +115,21 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { if (playables.size() == 1) { ability = playables.get(0); } else { - ability = playables.get(rnd.nextInt(playables.size())); + ability = playables.get(RandomUtil.nextInt(playables.size())); } List options = getPlayableOptions(ability, game); if (!options.isEmpty()) { if (options.size() == 1) { ability = options.get(0); } else { - ability = options.get(rnd.nextInt(options.size())); + ability = options.get(RandomUtil.nextInt(options.size())); } } if (ability.getManaCosts().getVariableCosts().size() > 0) { int amount = getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost(); if (amount > 0) { ability = ability.copy(); - ability.getManaCostsToPay().add(new GenericManaCost(rnd.nextInt(amount))); + ability.getManaCostsToPay().add(new GenericManaCost(RandomUtil.nextInt(amount))); } } // check if ability kills player, if not then it's ok to play @@ -163,7 +163,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { if (options.size() == 1) { ability = options.get(0); } else { - ability = options.get(rnd.nextInt(options.size())); + ability = options.get(RandomUtil.nextInt(options.size())); } } if (ability.isUsesStack()) { @@ -192,7 +192,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { List attackersList = super.getAvailableAttackers(defenderId, game); //use binary digits to calculate powerset of attackers int powerElements = (int) Math.pow(2, attackersList.size()); - int value = rnd.nextInt(powerElements); + int value = RandomUtil.nextInt(powerElements); StringBuilder binary = new StringBuilder(); binary.append(Integer.toBinaryString(value)); while (binary.length() < attackersList.size()) { @@ -219,7 +219,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { List blockers = getAvailableBlockers(game); for (Permanent blocker : blockers) { - int check = rnd.nextInt(numGroups + 1); + int check = RandomUtil.nextInt(numGroups + 1); if (check < numGroups) { CombatGroup group = game.getCombat().getGroups().get(check); if (group.getAttackers().size() > 0) { @@ -245,7 +245,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return true; } Iterator it = possibleTargets.iterator(); - int targetNum = rnd.nextInt(possibleTargets.size()); + int targetNum = RandomUtil.nextInt(possibleTargets.size()); UUID targetId = it.next(); for (int i = 0; i < targetNum; i++) { targetId = it.next(); @@ -260,7 +260,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return false; } if (!target.isRequired(source)) { - if (rnd.nextInt(possibleTargets.size() + 1) == 0) { + if (RandomUtil.nextInt(possibleTargets.size() + 1) == 0) { return false; } } @@ -269,7 +269,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return true; } Iterator it = possibleTargets.iterator(); - int targetNum = rnd.nextInt(possibleTargets.size()); + int targetNum = RandomUtil.nextInt(possibleTargets.size()); UUID targetId = it.next(); for (int i = 0; i < targetNum; i++) { targetId = it.next(); @@ -305,7 +305,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return false; } Iterator it = possibleTargets.iterator(); - int targetNum = rnd.nextInt(possibleTargets.size()); + int targetNum = RandomUtil.nextInt(possibleTargets.size()); UUID targetId = it.next(); for (int i = 0; i < targetNum; i++) { targetId = it.next(); @@ -338,7 +338,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return !target.isRequired(source); } if (!target.isRequired(source)) { - if (rnd.nextInt(possibleTargets.size() + 1) == 0) { + if (RandomUtil.nextInt(possibleTargets.size() + 1) == 0) { return false; } } @@ -347,24 +347,24 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { return true; } Iterator it = possibleTargets.iterator(); - int targetNum = rnd.nextInt(possibleTargets.size()); + int targetNum = RandomUtil.nextInt(possibleTargets.size()); UUID targetId = it.next(); for (int i = 0; i < targetNum; i++) { targetId = it.next(); } - target.addTarget(targetId, rnd.nextInt(target.getAmountRemaining()) + 1, source, game); + target.addTarget(targetId, RandomUtil.nextInt(target.getAmountRemaining()) + 1, source, game); return true; } @Override public boolean chooseMulligan(Game game) { - return rnd.nextBoolean(); + return RandomUtil.nextBoolean(); } @Override public boolean chooseUse(Outcome outcome, String message, Ability source, Game game) { if (this.isHuman()) { - return rnd.nextBoolean(); + return RandomUtil.nextBoolean(); } return super.chooseUse(outcome, message, source, game); } @@ -372,7 +372,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public boolean choosePile(Outcome outcome, String message, List pile1, List pile2, Game game) { if (this.isHuman()) { - return rnd.nextBoolean(); + return RandomUtil.nextBoolean(); } return super.choosePile(outcome, message, pile1, pile2, game); } @@ -382,7 +382,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { if (this.isHuman()) { Iterator it = choice.getChoices().iterator(); String sChoice = it.next(); - int choiceNum = rnd.nextInt(choice.getChoices().size()); + int choiceNum = RandomUtil.nextInt(choice.getChoices().size()); for (int i = 0; i < choiceNum; i++) { sChoice = it.next(); } @@ -395,7 +395,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public int chooseReplacementEffect(Map rEffects, Game game) { if (this.isHuman()) { - return rnd.nextInt(rEffects.size()); + return RandomUtil.nextInt(rEffects.size()); } return super.chooseReplacementEffect(rEffects, game); } @@ -403,7 +403,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public TriggeredAbility chooseTriggeredAbility(List abilities, Game game) { if (this.isHuman()) { - return abilities.get(rnd.nextInt(abilities.size())); + return abilities.get(RandomUtil.nextInt(abilities.size())); } return super.chooseTriggeredAbility(abilities, game); } @@ -416,7 +416,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { if (modes.size() == 1) { return mode; } - int modeNum = rnd.nextInt(modes.getAvailableModes(source, game).size()); + int modeNum = RandomUtil.nextInt(modes.getAvailableModes(source, game).size()); for (int i = 0; i < modeNum; i++) { mode = it.next(); } @@ -428,7 +428,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public UUID chooseAttackerOrder(List attackers, Game game) { if (this.isHuman()) { - return attackers.get(rnd.nextInt(attackers.size())).getId(); + return attackers.get(RandomUtil.nextInt(attackers.size())).getId(); } return super.chooseAttackerOrder(attackers, game); } @@ -436,7 +436,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public UUID chooseBlockerOrder(List blockers, CombatGroup combatGroup, List blockerOrder, Game game) { if (this.isHuman()) { - return blockers.get(rnd.nextInt(blockers.size())).getId(); + return blockers.get(RandomUtil.nextInt(blockers.size())).getId(); } return super.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game); } @@ -452,8 +452,8 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { targetId = targets.get(0); amount = remainingDamage; } else { - targetId = targets.get(rnd.nextInt(targets.size())); - amount = rnd.nextInt(damage + 1); + targetId = targets.get(RandomUtil.nextInt(targets.size())); + amount = RandomUtil.nextInt(damage + 1); } Permanent permanent = game.getPermanent(targetId); if (permanent != null) { @@ -476,7 +476,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public int getAmount(int min, int max, String message, Game game) { if (this.isHuman()) { - return rnd.nextInt(max - min) + min; + return RandomUtil.nextInt(max - min) + min; } return super.getAmount(min, max, message, game); } diff --git a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java index 97f1f39eff..7893fbca3d 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -6,6 +6,7 @@ import mage.cards.repository.CardRepository; import mage.constants.Zone; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; import java.io.File; import java.util.Date; @@ -95,10 +96,9 @@ public class SystemUtil { continue; } - Random random = new Random(); Set cardsToLoad = new HashSet<>(); for (int i = 0; i < amount; i++) { - CardInfo cardInfo = cards.get(random.nextInt(cards.size())); + CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size())); Card card = cardInfo != null ? cardInfo.getCard() : null; if (card != null) { cardsToLoad.add(card); diff --git a/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java b/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java index c09a17e451..12ea275644 100644 --- a/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java +++ b/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java @@ -38,6 +38,7 @@ import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.constants.Rarity; import mage.constants.SetType; +import mage.util.RandomUtil; /** * @@ -73,7 +74,7 @@ public class ShadowsOverInnistrad extends ExpansionSet { public void addDoubleFace(List booster) { for (int i = 0; i < numBoosterDoubleFaced; i++) { List doubleFacedCards; - if (rnd.nextInt(15) < 10) { + if (RandomUtil.nextInt(15) < 10) { doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.COMMON); } else { doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.UNCOMMON); @@ -99,14 +100,14 @@ public class ShadowsOverInnistrad extends ExpansionSet { @Override public int getNumberOfSpecialCommons() { // Then about an eighth of the packs will have a second double-faced card, which will be a rare or mythic rare. - return rnd.nextInt(8) == 0 ? 1 : 0; + return RandomUtil.nextInt(8) == 0 ? 1 : 0; } @Override public void addSpecialCommon(List booster, int number) { // number is here always 1 List doubleFacedCards; - if (rnd.nextInt(8) > 0) { + if (RandomUtil.nextInt(8) > 0) { doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.RARE); } else { doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.MYTHIC); diff --git a/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java b/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java index 3685618248..2d50e66ab1 100644 --- a/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java +++ b/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java @@ -48,6 +48,7 @@ import mage.players.Player; import mage.players.PlayerList; import mage.target.Target; import mage.target.TargetPermanent; +import mage.util.RandomUtil; /** * @@ -76,7 +77,6 @@ public class WhimsOfTheFates extends CardImpl { class WhimsOfTheFateEffect extends OneShotEffect { - protected static Random rnd = new Random(); public WhimsOfTheFateEffect() { super(Outcome.Detriment); @@ -173,7 +173,7 @@ class WhimsOfTheFateEffect extends OneShotEffect { Player player = game.getPlayer(playerPiles.getKey()); if (player != null) { // decide which pile to sacrifice - int sacrificePile = rnd.nextInt(3) + 1; // random number from 1 - 3 + int sacrificePile = RandomUtil.nextInt(3) + 1; // random number from 1 - 3 game.informPlayers(new StringBuilder(player.getLogName()).append(" sacrifices pile number ").append(sacrificePile).toString()); for (UUID permanentId : playerPiles.getValue().get(sacrificePile)) { Permanent permanent = game.getPermanent(permanentId); diff --git a/Mage.Sets/src/mage/sets/commander/RuhanOfTheFomori.java b/Mage.Sets/src/mage/sets/commander/RuhanOfTheFomori.java index b215a1ba77..8e051a9961 100644 --- a/Mage.Sets/src/mage/sets/commander/RuhanOfTheFomori.java +++ b/Mage.Sets/src/mage/sets/commander/RuhanOfTheFomori.java @@ -47,6 +47,7 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; +import mage.util.RandomUtil; /** * @@ -98,10 +99,9 @@ class RuhanOfTheFomoriEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Random random = new Random(); List opponents = new ArrayList<>(); opponents.addAll(game.getOpponents(controller.getId())); - Player opponent = game.getPlayer(opponents.get(random.nextInt(opponents.size()))); + Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size()))); if (opponent != null) { ContinuousEffect effect = new AttacksIfAbleTargetPlayerSourceEffect(); effect.setTargetPointer(new FixedTarget(opponent.getId())); diff --git a/Mage.Sets/src/mage/sets/commander2014/RavingDead.java b/Mage.Sets/src/mage/sets/commander2014/RavingDead.java index a46544c436..b4bcb686eb 100644 --- a/Mage.Sets/src/mage/sets/commander2014/RavingDead.java +++ b/Mage.Sets/src/mage/sets/commander2014/RavingDead.java @@ -49,6 +49,7 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; +import mage.util.RandomUtil; /** * @@ -102,10 +103,9 @@ class RavingDeadEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Random random = new Random(); List opponents = new ArrayList<>(); opponents.addAll(game.getOpponents(controller.getId())); - Player opponent = game.getPlayer(opponents.get(random.nextInt(opponents.size()))); + Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size()))); if (opponent != null) { ContinuousEffect effect = new AttacksIfAbleTargetPlayerSourceEffect(); effect.setTargetPointer(new FixedTarget(opponent.getId())); diff --git a/Mage.Sets/src/mage/sets/darkascension/HauntedFengraf.java b/Mage.Sets/src/mage/sets/darkascension/HauntedFengraf.java index 80e8777b2e..f1579c7735 100644 --- a/Mage.Sets/src/mage/sets/darkascension/HauntedFengraf.java +++ b/Mage.Sets/src/mage/sets/darkascension/HauntedFengraf.java @@ -46,6 +46,7 @@ import mage.cards.CardImpl; import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -98,8 +99,7 @@ class HauntedFengrafEffect extends OneShotEffect { if (player != null) { Card[] cards = player.getGraveyard().getCards(new FilterCreatureCard(), game).toArray(new Card[0]); if (cards.length > 0) { - Random rnd = new Random(); - Card card = cards[rnd.nextInt(cards.length)]; + Card card = cards[RandomUtil.nextInt(cards.length)]; card.moveToZone(Zone.HAND, source.getSourceId(), game, true); game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName()); return true; diff --git a/Mage.Sets/src/mage/sets/eldritchmoon/RideDown.java b/Mage.Sets/src/mage/sets/eldritchmoon/RideDown.java index fabce419d1..3ac0e21d3d 100644 --- a/Mage.Sets/src/mage/sets/eldritchmoon/RideDown.java +++ b/Mage.Sets/src/mage/sets/eldritchmoon/RideDown.java @@ -27,6 +27,8 @@ */ package mage.sets.eldritchmoon; +import mage.sets.EldritchMoon; + import java.util.UUID; /** diff --git a/Mage.Sets/src/mage/sets/innistrad/CharmbreakerDevils.java b/Mage.Sets/src/mage/sets/innistrad/CharmbreakerDevils.java index 839dc8f3f5..25f5ff325e 100644 --- a/Mage.Sets/src/mage/sets/innistrad/CharmbreakerDevils.java +++ b/Mage.Sets/src/mage/sets/innistrad/CharmbreakerDevils.java @@ -49,6 +49,7 @@ import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; import mage.game.events.GameEvent.EventType; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -114,8 +115,7 @@ class CharmbreakerDevilsEffect extends OneShotEffect { new CardTypePredicate(CardType.SORCERY))); Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]); if (cards.length > 0) { - Random rnd = new Random(); - Card card = cards[rnd.nextInt(cards.length)]; + Card card = cards[RandomUtil.nextInt(cards.length)]; card.moveToZone(Zone.HAND, source.getSourceId(), game, true); game.informPlayers(new StringBuilder("Charmbreaker Devils: ").append(card.getName()).append(" returned to the hand of ").append(player.getLogName()).toString()); return true; diff --git a/Mage.Sets/src/mage/sets/innistrad/Ghoulraiser.java b/Mage.Sets/src/mage/sets/innistrad/Ghoulraiser.java index a5cfba8f1e..2ada4c0cb4 100644 --- a/Mage.Sets/src/mage/sets/innistrad/Ghoulraiser.java +++ b/Mage.Sets/src/mage/sets/innistrad/Ghoulraiser.java @@ -43,6 +43,7 @@ import mage.filter.FilterCard; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -96,8 +97,7 @@ class GhoulraiserEffect extends OneShotEffect { filter.add(new SubtypePredicate("Zombie")); Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]); if (cards.length > 0) { - Random rnd = new Random(); - Card card = cards[rnd.nextInt(cards.length)]; + Card card = cards[RandomUtil.nextInt(cards.length)]; card.moveToZone(Zone.HAND, source.getSourceId(), game, true); game.informPlayers(card.getName() + "returned to the hand of" + player.getLogName()); return true; diff --git a/Mage.Sets/src/mage/sets/innistrad/MoldgrafMonstrosity.java b/Mage.Sets/src/mage/sets/innistrad/MoldgrafMonstrosity.java index 2e4d4db01d..bc16b5b3c4 100644 --- a/Mage.Sets/src/mage/sets/innistrad/MoldgrafMonstrosity.java +++ b/Mage.Sets/src/mage/sets/innistrad/MoldgrafMonstrosity.java @@ -45,6 +45,7 @@ import mage.cards.CardImpl; import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -116,7 +117,7 @@ class MoldgrafMonstrosityEffect extends OneShotEffect { return null; } int i = 0; - int pick = new Random().nextInt(cards.size()); + int pick = RandomUtil.nextInt(cards.size()); for (Card card : cards) { if (i == pick) { return card; diff --git a/Mage.Sets/src/mage/sets/innistrad/WoodlandSleuth.java b/Mage.Sets/src/mage/sets/innistrad/WoodlandSleuth.java index 58bfb1279a..b956488b40 100644 --- a/Mage.Sets/src/mage/sets/innistrad/WoodlandSleuth.java +++ b/Mage.Sets/src/mage/sets/innistrad/WoodlandSleuth.java @@ -45,6 +45,7 @@ import mage.cards.CardImpl; import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -101,8 +102,7 @@ class WoodlandSleuthEffect extends OneShotEffect { if (player != null) { Card[] cards = player.getGraveyard().getCards(new FilterCreatureCard(), game).toArray(new Card[0]); if (cards.length > 0) { - Random rnd = new Random(); - Card card = cards[rnd.nextInt(cards.length)]; + Card card = cards[RandomUtil.nextInt(cards.length)]; card.moveToZone(Zone.HAND, source.getSourceId(), game, true); game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName()); return true; diff --git a/Mage.Sets/src/mage/sets/magic2010/CapriciousEfreet.java b/Mage.Sets/src/mage/sets/magic2010/CapriciousEfreet.java index 302de2ba8c..df5050cd3e 100644 --- a/Mage.Sets/src/mage/sets/magic2010/CapriciousEfreet.java +++ b/Mage.Sets/src/mage/sets/magic2010/CapriciousEfreet.java @@ -44,6 +44,7 @@ import mage.filter.predicate.permanent.ControllerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; +import mage.util.RandomUtil; /** * @@ -115,8 +116,7 @@ class CapriciousEfreetEffect extends OneShotEffect { } if (!targetPermanents.isEmpty()) { - Random random = new Random(); - permanent = targetPermanents.get(random.nextInt(targetPermanents.size())); + permanent = targetPermanents.get(RandomUtil.nextInt(targetPermanents.size())); permanent.destroy(source.getSourceId(), game, false); return true; } diff --git a/Mage.Sets/src/mage/sets/magic2012/Scrambleverse.java b/Mage.Sets/src/mage/sets/magic2012/Scrambleverse.java index f3ba25b30d..b83a8cfd60 100644 --- a/Mage.Sets/src/mage/sets/magic2012/Scrambleverse.java +++ b/Mage.Sets/src/mage/sets/magic2012/Scrambleverse.java @@ -43,6 +43,7 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.PlayerList; import mage.target.targetpointer.FixedTarget; +import mage.util.RandomUtil; /** * @@ -81,11 +82,10 @@ class ScrambleverseEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Random random = new Random(); PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game); int count = players.size(); for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) { - ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(random.nextInt(count))); + ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count))); effect.setTargetPointer(new FixedTarget(permanent.getId())); game.addEffect(effect, source); permanent.untap(game); diff --git a/Mage.Sets/src/mage/sets/magic2014/MoltenBirth.java b/Mage.Sets/src/mage/sets/magic2014/MoltenBirth.java index ff8fc7e9bb..df4221518d 100644 --- a/Mage.Sets/src/mage/sets/magic2014/MoltenBirth.java +++ b/Mage.Sets/src/mage/sets/magic2014/MoltenBirth.java @@ -41,6 +41,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.token.Token; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -106,7 +107,7 @@ class ElementalToken extends Token { public ElementalToken() { super("Elemental", "1/1 red Elemental creature"); this.setOriginalExpansionSetCode("M14"); - this.setTokenType(new Random().nextInt(2) + 1); + this.setTokenType(RandomUtil.nextInt(2) + 1); cardType.add(CardType.CREATURE); color.setRed(true); subtype.add("Elemental"); diff --git a/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java b/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java index 68c7595f22..24b2f71d8d 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java +++ b/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java @@ -41,6 +41,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -83,7 +84,7 @@ class KrarksThumbEffect extends ReplacementEffectImpl { Player player = game.getPlayer(event.getPlayerId()); if (player != null) { // because second flip is ignored it may not be done by the player method - boolean secondCoinFlip = new Random().nextBoolean(); + boolean secondCoinFlip = RandomUtil.nextBoolean(); if (!game.isSimulation()) { game.informPlayers("[Flip a coin] " + player.getLogName() + (secondCoinFlip ? " won (head)." : " lost (tail).")); } diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/SurrealMemoir.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/SurrealMemoir.java index cdc512d4cb..9bd362867e 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/SurrealMemoir.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/SurrealMemoir.java @@ -42,6 +42,7 @@ import mage.filter.FilterCard; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -93,8 +94,7 @@ class SurrealMemoirEffect extends OneShotEffect { filter.add(new CardTypePredicate(CardType.INSTANT)); Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]); if (cards.length > 0) { - Random rnd = new Random(); - Card card = cards[rnd.nextInt(cards.length)]; + Card card = cards[RandomUtil.nextInt(cards.length)]; card.moveToZone(Zone.HAND, source.getSourceId(), game, true); game.informPlayers(card.getName() + "returned to the hand of" + player.getLogName()); return true; diff --git a/Mage.Sets/src/mage/sets/scourge/GripOfChaos.java b/Mage.Sets/src/mage/sets/scourge/GripOfChaos.java index 0f846931d0..4f7131948d 100644 --- a/Mage.Sets/src/mage/sets/scourge/GripOfChaos.java +++ b/Mage.Sets/src/mage/sets/scourge/GripOfChaos.java @@ -47,6 +47,7 @@ import mage.game.events.GameEvent.EventType; import mage.game.stack.StackObject; import mage.target.Target; import mage.target.targetpointer.FixedTarget; +import mage.util.RandomUtil; /** * @@ -154,7 +155,7 @@ class GripOfChaosEffect extends OneShotEffect { Set possibleTargets = target.possibleTargets(source.getSourceId(), source.getControllerId(), game); if (possibleTargets.size() > 0) { int i = 0; - int rnd = new Random().nextInt(possibleTargets.size()); + int rnd = RandomUtil.nextInt(possibleTargets.size()); Iterator it = possibleTargets.iterator(); while (i < rnd) { it.next(); diff --git a/Mage.Sets/src/mage/sets/shadowmoor/WildSwing.java b/Mage.Sets/src/mage/sets/shadowmoor/WildSwing.java index 3b3c4ac10a..a6e9ac5718 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/WildSwing.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/WildSwing.java @@ -43,6 +43,7 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.Target; import mage.target.TargetPermanent; +import mage.util.RandomUtil; /** * @@ -98,8 +99,8 @@ class WildSwingEffect extends OneShotEffect { if (!source.getTargets().isEmpty() && sourceObject != null) { Target target = source.getTargets().get(0); if (target != null && !target.getTargets().isEmpty()) { - Random rnd = new Random(); - Permanent targetPermanent = game.getPermanent(target.getTargets().get(rnd.nextInt(target.getTargets().size()))); + + Permanent targetPermanent = game.getPermanent(target.getTargets().get(RandomUtil.nextInt(target.getTargets().size()))); if (targetPermanent != null) { game.informPlayers(sourceObject.getLogName() + ": The randomly chosen target to destroy is " + targetPermanent.getLogName()); targetPermanent.destroy(source.getSourceId(), game, false); diff --git a/Mage/src/main/java/mage/cards/CardsImpl.java b/Mage/src/main/java/mage/cards/CardsImpl.java index 46eeb4984d..9719114d32 100644 --- a/Mage/src/main/java/mage/cards/CardsImpl.java +++ b/Mage/src/main/java/mage/cards/CardsImpl.java @@ -41,6 +41,7 @@ import java.util.Set; import java.util.UUID; import mage.filter.FilterCard; import mage.game.Game; +import mage.util.RandomUtil; import mage.util.ThreadLocalStringBuilder; /** @@ -51,7 +52,6 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl private static final ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(200); - private static Random rnd = new Random(); private UUID ownerId; public CardsImpl() { @@ -114,7 +114,7 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl return null; } UUID[] cards = this.toArray(new UUID[this.size()]); - return game.getCard(cards[rnd.nextInt(cards.length)]); + return game.getCard(cards[RandomUtil.nextInt(cards.length)]); } @Override diff --git a/Mage/src/main/java/mage/cards/ExpansionSet.java b/Mage/src/main/java/mage/cards/ExpansionSet.java index a81f82ce04..3b4e004d9c 100644 --- a/Mage/src/main/java/mage/cards/ExpansionSet.java +++ b/Mage/src/main/java/mage/cards/ExpansionSet.java @@ -38,13 +38,13 @@ import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.constants.Rarity; import mage.constants.SetType; +import mage.util.RandomUtil; /** * @author BetaSteward_at_googlemail.com */ public abstract class ExpansionSet implements Serializable { - protected static Random rnd = new Random(); protected String name; protected String code; @@ -136,7 +136,7 @@ public abstract class ExpansionSet implements Serializable { protected void addToBooster(List booster, List cards) { if (!cards.isEmpty()) { - CardInfo cardInfo = cards.remove(rnd.nextInt(cards.size())); + CardInfo cardInfo = cards.remove(RandomUtil.nextInt(cards.size())); if (cardInfo != null) { Card card = cardInfo.getCard(); if (card != null) { @@ -156,7 +156,7 @@ public abstract class ExpansionSet implements Serializable { List specialLands = getSpecialLand(); List basicLands = getCardsByRarity(Rarity.LAND); for (int i = 0; i < numBoosterLands; i++) { - if (ratioBoosterSpecialLand > 0 && rnd.nextInt(ratioBoosterSpecialLand) == 0 && specialLands != null) { + if (ratioBoosterSpecialLand > 0 && RandomUtil.nextInt(ratioBoosterSpecialLand) == 0 && specialLands != null) { addToBooster(booster, specialLands); } else { addToBooster(booster, basicLands); @@ -183,7 +183,7 @@ public abstract class ExpansionSet implements Serializable { List rares = getCardsByRarity(Rarity.RARE); List mythics = getCardsByRarity(Rarity.MYTHIC); for (int i = 0; i < numBoosterRare; i++) { - if (ratioBoosterMythic > 0 && rnd.nextInt(ratioBoosterMythic) == 0) { + if (ratioBoosterMythic > 0 && RandomUtil.nextInt(ratioBoosterMythic) == 0) { addToBooster(booster, mythics); } else { addToBooster(booster, rares); @@ -208,11 +208,11 @@ public abstract class ExpansionSet implements Serializable { for (int i = 0; i < numBoosterDoubleFaced; i++) { CardCriteria criteria = new CardCriteria(); criteria.setCodes(this.code).doubleFaced(true); - if (rnd.nextInt(15) < 10) { + if (RandomUtil.nextInt(15) < 10) { criteria.rarities(Rarity.COMMON); - } else if (rnd.nextInt(5) < 4) { + } else if (RandomUtil.nextInt(5) < 4) { criteria.rarities(Rarity.UNCOMMON); - } else if (rnd.nextInt(8) < 7) { + } else if (RandomUtil.nextInt(8) < 7) { criteria.rarities(Rarity.RARE); } else { criteria.rarities(Rarity.MYTHIC); @@ -265,7 +265,7 @@ public abstract class ExpansionSet implements Serializable { } if (specialCards > 0) { for (int i = 0; i < numBoosterSpecial; i++) { - if (rnd.nextInt(15) < 10) { + if (RandomUtil.nextInt(15) < 10) { if (specialCommon != null && !specialCommon.isEmpty()) { addToBooster(booster, specialCommon); } else { @@ -273,7 +273,7 @@ public abstract class ExpansionSet implements Serializable { } continue; } - if (rnd.nextInt(4) < 3) { + if (RandomUtil.nextInt(4) < 3) { if (specialUncommon != null && !specialUncommon.isEmpty()) { addToBooster(booster, specialUncommon); } else { @@ -281,7 +281,7 @@ public abstract class ExpansionSet implements Serializable { } continue; } - if (rnd.nextInt(8) < 7) { + if (RandomUtil.nextInt(8) < 7) { if (specialRare != null && !specialRare.isEmpty()) { addToBooster(booster, specialRare); } else { @@ -291,7 +291,7 @@ public abstract class ExpansionSet implements Serializable { } if (specialMythic != null && !specialMythic.isEmpty()) { if (specialBonus != null && !specialBonus.isEmpty()) { - if (rnd.nextInt(3) < 2) { + if (RandomUtil.nextInt(3) < 2) { addToBooster(booster, specialMythic); continue; } diff --git a/Mage/src/main/java/mage/cards/Sets.java b/Mage/src/main/java/mage/cards/Sets.java index 0ddb5a8828..41b605973e 100644 --- a/Mage/src/main/java/mage/cards/Sets.java +++ b/Mage/src/main/java/mage/cards/Sets.java @@ -45,6 +45,7 @@ import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.util.ClassScanner; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -55,7 +56,6 @@ public class Sets extends HashMap { private static final Logger logger = Logger.getLogger(Sets.class); private static final Sets fINSTANCE = new Sets(); - protected static Random rnd = new Random(); public static Sets getInstance() { return fINSTANCE; @@ -111,7 +111,7 @@ public class Sets extends HashMap { int tries = 0; List cardPool = new ArrayList<>(); while (count < cardsCount) { - CardInfo cardInfo = cards.get(rnd.nextInt(cards.size())); + CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size())); Card card = cardInfo != null ? cardInfo.getCard() : null; if (card != null) { cardPool.add(card); diff --git a/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java index 7ee643ff02..0f738099ad 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java +++ b/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java @@ -34,6 +34,7 @@ import mage.cards.decks.DeckCardLists; import mage.cards.repository.CardCriteria; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; +import mage.util.RandomUtil; /** * @@ -71,7 +72,7 @@ public class MWSDeckImporter extends DeckImporter { List cards = null; cards = CardRepository.instance.findCards(criteria); if (!cards.isEmpty()) { - cardInfo = cards.get(new Random().nextInt(cards.size())); + cardInfo = cards.get(RandomUtil.nextInt(cards.size())); } } if (cardInfo == null) { diff --git a/Mage/src/main/java/mage/cards/repository/CardRepository.java b/Mage/src/main/java/mage/cards/repository/CardRepository.java index 448771998b..278d9ea027 100644 --- a/Mage/src/main/java/mage/cards/repository/CardRepository.java +++ b/Mage/src/main/java/mage/cards/repository/CardRepository.java @@ -48,6 +48,7 @@ import java.util.TreeSet; import java.util.concurrent.Callable; import mage.constants.CardType; import mage.constants.SetType; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -65,7 +66,6 @@ public enum CardRepository { // raise this if new cards were added to the server private static final long CARD_CONTENT_VERSION = 57; - private final Random random = new Random(); private Dao cardDao; private Set classNames; @@ -317,7 +317,7 @@ public enum CardRepository { public CardInfo findCard(String name) { List cards = findCards(name); if (!cards.isEmpty()) { - return cards.get(random.nextInt(cards.size())); + return cards.get(RandomUtil.nextInt(cards.size())); } return null; } diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 2e3b727214..16227b0073 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -124,6 +124,7 @@ import mage.target.TargetPermanent; import mage.target.TargetPlayer; import mage.util.GameLog; import mage.util.MessageToClient; +import mage.util.RandomUtil; import mage.util.functions.ApplyToPermanent; import mage.watchers.Watchers; import mage.watchers.common.BlockedAttackerWatcher; @@ -159,7 +160,6 @@ public abstract class GameImpl implements Game, Serializable { FILTER_LEGENDARY.add(new SupertypePredicate("Legendary")); } - private static Random rnd = new Random(); private transient Object customData; protected boolean simulation = false; @@ -1098,7 +1098,7 @@ public abstract class GameImpl implements Game, Serializable { UUID[] players = getPlayers().keySet().toArray(new UUID[0]); UUID playerId; while (!hasEnded()) { - playerId = players[rnd.nextInt(players.length)]; + playerId = players[RandomUtil.nextInt(players.length)]; Player player = getPlayer(playerId); if (player != null && player.isInGame()) { fireInformEvent(state.getPlayer(playerId).getLogName() + " won the toss"); diff --git a/Mage/src/main/java/mage/game/draft/DraftCube.java b/Mage/src/main/java/mage/game/draft/DraftCube.java index e5df9e6680..2e8fddc109 100644 --- a/Mage/src/main/java/mage/game/draft/DraftCube.java +++ b/Mage/src/main/java/mage/game/draft/DraftCube.java @@ -34,6 +34,7 @@ import mage.cards.Card; import mage.cards.repository.CardCriteria; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -71,7 +72,6 @@ public abstract class DraftCube { private static final Logger logger = Logger.getLogger(DraftCube.class); - private static final Random rnd = new Random(); private final String name; private final int boosterSize = 15; @@ -100,7 +100,7 @@ public abstract class DraftCube { boolean done = false; int notValid = 0; while (!done) { - int index = rnd.nextInt(leftCubeCards.size()); + int index = RandomUtil.nextInt(leftCubeCards.size()); CardIdentity cardId = leftCubeCards.get(index); leftCubeCards.remove(index); if (!cardId.getName().isEmpty()) { diff --git a/Mage/src/main/java/mage/game/draft/DraftImpl.java b/Mage/src/main/java/mage/game/draft/DraftImpl.java index babf5359bd..f0a73ce0d9 100644 --- a/Mage/src/main/java/mage/game/draft/DraftImpl.java +++ b/Mage/src/main/java/mage/game/draft/DraftImpl.java @@ -121,6 +121,7 @@ public abstract class DraftImpl implements Draft { for(UUID playerId : players.keySet()) { table.add(playerId); } + table.setCurrent(currentId); } if (oldDraftPlayer.isPicking()) { diff --git a/Mage/src/main/java/mage/game/match/MatchImpl.java b/Mage/src/main/java/mage/game/match/MatchImpl.java index a864f1f5c6..d3d4f1091a 100644 --- a/Mage/src/main/java/mage/game/match/MatchImpl.java +++ b/Mage/src/main/java/mage/game/match/MatchImpl.java @@ -45,6 +45,7 @@ import mage.game.result.ResultProtos.MatchProto; import mage.game.result.ResultProtos.MatchQuitStatus; import mage.players.Player; import mage.util.DateFormat; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -243,7 +244,7 @@ public abstract class MatchImpl implements Match { } protected void shufflePlayers() { - Collections.shuffle(this.players, new Random()); + Collections.shuffle(this.players, RandomUtil.getRandom()); } @Override diff --git a/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java b/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java index 2517090bc6..222201ef11 100644 --- a/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java @@ -31,6 +31,7 @@ package mage.game.permanent.token; import java.util.Random; import mage.constants.CardType; import mage.MageInt; +import mage.util.RandomUtil; /** * @@ -41,7 +42,7 @@ public class CentaurToken extends Token { public CentaurToken() { super("Centaur", "3/3 green Centaur creature token"); cardType.add(CardType.CREATURE); - setTokenType(new Random().nextInt(2) +1); // randomly take image 1 or 2 + setTokenType(RandomUtil.nextInt(2) +1); // randomly take image 1 or 2 color.setGreen(true); subtype.add("Centaur"); power = new MageInt(3); diff --git a/Mage/src/main/java/mage/game/permanent/token/ClueArtifactToken.java b/Mage/src/main/java/mage/game/permanent/token/ClueArtifactToken.java index d1e64b27f8..0e2ffa5785 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ClueArtifactToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ClueArtifactToken.java @@ -38,6 +38,7 @@ import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.constants.CardType; import mage.constants.Zone; +import mage.util.RandomUtil; /** * @@ -69,10 +70,10 @@ public class ClueArtifactToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("SOI")) { - this.setTokenType(new Random().nextInt(6) + 1); // 6 different images + this.setTokenType(RandomUtil.nextInt(6) + 1); // 6 different images } if (getOriginalExpansionSetCode().equals("EDM")) { - this.setTokenType(new Random().nextInt(6) + 1); // 6 different images + this.setTokenType(RandomUtil.nextInt(6) + 1); // 6 different images } } diff --git a/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java b/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java index 7b347d7de5..c2564d3669 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java @@ -37,6 +37,7 @@ import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.mana.SimpleManaAbility; import mage.constants.CardType; import mage.constants.Zone; +import mage.util.RandomUtil; /** * @@ -65,10 +66,10 @@ public class EldraziScionToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("BFZ")) { - this.setTokenType(new Random().nextInt(3) + 1); // 3 different images + this.setTokenType(RandomUtil.nextInt(3) + 1); // 3 different images } if (getOriginalExpansionSetCode().equals("OGW")) { - this.setTokenType(new Random().nextInt(6) + 1); // 6 different images + this.setTokenType(RandomUtil.nextInt(6) + 1); // 6 different images } } diff --git a/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java b/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java index 2ec29418c6..43956bef29 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java @@ -37,6 +37,7 @@ import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.mana.SimpleManaAbility; import mage.constants.CardType; import mage.constants.Zone; +import mage.util.RandomUtil; /** * @@ -61,6 +62,6 @@ public class EldraziSpawnToken extends Token { availableImageSetCodes = tokenImageSets; // Get one of the three possible token images - this.setTokenType(new Random().nextInt(3) + 1); + this.setTokenType(RandomUtil.nextInt(3) + 1); } } \ No newline at end of file diff --git a/Mage/src/main/java/mage/game/permanent/token/SoldierToken.java b/Mage/src/main/java/mage/game/permanent/token/SoldierToken.java index 8ce18a7b7a..ede064baf2 100644 --- a/Mage/src/main/java/mage/game/permanent/token/SoldierToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/SoldierToken.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Random; import mage.MageInt; import mage.constants.CardType; +import mage.util.RandomUtil; /** * @@ -62,7 +63,7 @@ public class SoldierToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("THS")) { - this.setTokenType(new Random().nextInt(2) + 1); + this.setTokenType(RandomUtil.nextInt(2) + 1); } } diff --git a/Mage/src/main/java/mage/game/permanent/token/ThopterColorlessToken.java b/Mage/src/main/java/mage/game/permanent/token/ThopterColorlessToken.java index 695be8d111..3e48856803 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ThopterColorlessToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ThopterColorlessToken.java @@ -34,6 +34,7 @@ import java.util.Random; import mage.MageInt; import mage.abilities.keyword.FlyingAbility; import mage.constants.CardType; +import mage.util.RandomUtil; /** * @@ -63,7 +64,7 @@ public class ThopterColorlessToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("ORI")) { - this.setTokenType(new Random().nextInt(2) + 1); + this.setTokenType(RandomUtil.nextInt(2) + 1); } } diff --git a/Mage/src/main/java/mage/game/permanent/token/Token.java b/Mage/src/main/java/mage/game/permanent/token/Token.java index 84dfc61367..012f07187f 100644 --- a/Mage/src/main/java/mage/game/permanent/token/Token.java +++ b/Mage/src/main/java/mage/game/permanent/token/Token.java @@ -46,6 +46,7 @@ import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; import mage.game.permanent.PermanentToken; import mage.players.Player; +import mage.util.RandomUtil; public class Token extends MageObjectImpl { @@ -290,7 +291,7 @@ public class Token extends MageObjectImpl { // we should not set random set if appropriate set is already used if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty() || !availableImageSetCodes.contains(getOriginalExpansionSetCode())) { - setOriginalExpansionSetCode(availableImageSetCodes.get(new Random().nextInt(availableImageSetCodes.size()))); + setOriginalExpansionSetCode(availableImageSetCodes.get(RandomUtil.nextInt(availableImageSetCodes.size()))); } } } else { diff --git a/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java b/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java index 5ddc1c3aa2..6a34f22d33 100644 --- a/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.Random; import mage.MageInt; import mage.constants.CardType; +import mage.util.RandomUtil; /** * @@ -62,7 +63,7 @@ public class WarriorToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("KTK")) { - this.setTokenType(new Random().nextInt(2) + 1); + this.setTokenType(RandomUtil.nextInt(2) + 1); } } } diff --git a/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java b/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java index fec1a2d90c..8da3f8ad3d 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Random; import mage.MageInt; import mage.constants.CardType; +import mage.util.RandomUtil; /** * @@ -61,13 +62,13 @@ public class ZombieToken extends Token { public void setExpansionSetCodeForImage(String code) { super.setExpansionSetCodeForImage(code); if (getOriginalExpansionSetCode().equals("ISD")) { - this.setTokenType(new Random().nextInt(3) + 1); + this.setTokenType(RandomUtil.nextInt(3) + 1); } if (getOriginalExpansionSetCode().equals("C14")) { this.setTokenType(2); } if (getOriginalExpansionSetCode().equals("EMN")) { - this.setTokenType(new Random().nextInt(4) + 1); + this.setTokenType(RandomUtil.nextInt(4) + 1); } } diff --git a/Mage/src/main/java/mage/game/tournament/TournamentImpl.java b/Mage/src/main/java/mage/game/tournament/TournamentImpl.java index ae2fea34ce..ebc7faf589 100644 --- a/Mage/src/main/java/mage/game/tournament/TournamentImpl.java +++ b/Mage/src/main/java/mage/game/tournament/TournamentImpl.java @@ -57,6 +57,7 @@ import mage.game.result.ResultProtos.MatchQuitStatus; import mage.game.result.ResultProtos.TourneyProto; import mage.game.result.ResultProtos.TourneyRoundProto; import mage.players.Player; +import mage.util.RandomUtil; import org.apache.log4j.Logger; /** @@ -68,7 +69,6 @@ public abstract class TournamentImpl implements Tournament { protected UUID id = UUID.randomUUID(); protected List rounds = new CopyOnWriteArrayList<>(); protected Map players = new HashMap<>(); - protected static Random rnd = new Random(); protected String matchName; protected TournamentOptions options; protected TournamentType tournamentType; @@ -217,7 +217,7 @@ public abstract class TournamentImpl implements Tournament { private TournamentPlayer getNextAvailablePlayer(List roundPlayers, List playerWithByes) { TournamentPlayer nextPlayer; if (playerWithByes.isEmpty()) { - int i = rnd.nextInt(roundPlayers.size()); + int i = RandomUtil.nextInt(roundPlayers.size()); nextPlayer = roundPlayers.get(i); roundPlayers.remove(i); } else { // prefer players with byes to pair diff --git a/Mage/src/main/java/mage/players/Library.java b/Mage/src/main/java/mage/players/Library.java index 94db01427e..157a986bba 100644 --- a/Mage/src/main/java/mage/players/Library.java +++ b/Mage/src/main/java/mage/players/Library.java @@ -45,6 +45,7 @@ import mage.cards.Card; import mage.constants.Zone; import mage.filter.FilterCard; import mage.game.Game; +import mage.util.RandomUtil; /** * @@ -52,7 +53,6 @@ import mage.game.Game; */ public class Library implements Serializable { - private static Random rnd = new Random(); private boolean emptyDraw; private final Deque library = new ArrayDeque<>(); @@ -76,7 +76,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 = rnd.nextInt(n); + int r = RandomUtil.nextInt(n); UUID temp = shuffled[n]; shuffled[n] = shuffled[r]; shuffled[r] = temp; diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index d921af4bd4..12e72769ca 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -135,13 +135,13 @@ import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetDiscard; import mage.util.CardUtil; import mage.util.GameLog; +import mage.util.RandomUtil; import org.apache.log4j.Logger; public abstract class PlayerImpl implements Player, Serializable { private static final Logger logger = Logger.getLogger(PlayerImpl.class); - private static Random rnd = new Random(); private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); /** @@ -2329,7 +2329,7 @@ public abstract class PlayerImpl implements Player, Serializable { */ @Override public boolean flipCoin(Game game, ArrayList appliedEffects) { - boolean result = rnd.nextBoolean(); + boolean result = RandomUtil.nextBoolean(); if (!game.isSimulation()) { game.informPlayers("[Flip a coin] " + getLogName() + (result ? " won (head)." : " lost (tail).")); } diff --git a/Mage/src/main/java/mage/target/TargetImpl.java b/Mage/src/main/java/mage/target/TargetImpl.java index 6a9a4113c5..f3452954eb 100644 --- a/Mage/src/main/java/mage/target/TargetImpl.java +++ b/Mage/src/main/java/mage/target/TargetImpl.java @@ -47,6 +47,7 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.players.Player; +import mage.util.RandomUtil; /** * @@ -322,7 +323,7 @@ public abstract class TargetImpl implements Target { Set possibleTargets = possibleTargets(source.getSourceId(), playerId, game); if (possibleTargets.size() > 0) { int i = 0; - int rnd = new Random().nextInt(possibleTargets.size()); + int rnd = RandomUtil.nextInt(possibleTargets.size()); Iterator it = possibleTargets.iterator(); while (i < rnd) { it.next(); diff --git a/Mage/src/main/java/mage/util/RandomUtil.java b/Mage/src/main/java/mage/util/RandomUtil.java new file mode 100644 index 0000000000..2721d4e0e8 --- /dev/null +++ b/Mage/src/main/java/mage/util/RandomUtil.java @@ -0,0 +1,28 @@ +package mage.util; + +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +/** + * Created by IGOUDT on 5-9-2016. + */ +public class RandomUtil { + + private static ThreadLocalRandom random = ThreadLocalRandom.current(); + + public static Random getRandom(){ + return random; + } + + public static int nextInt(){ + return random.nextInt(); + } + + public static int nextInt(int max){ + return random.nextInt(max); + } + + public static boolean nextBoolean() { + return random.nextBoolean(); + } +} diff --git a/Mage/src/main/java/mage/util/TournamentUtil.java b/Mage/src/main/java/mage/util/TournamentUtil.java index 5e5c825525..c4f8ab2d1e 100644 --- a/Mage/src/main/java/mage/util/TournamentUtil.java +++ b/Mage/src/main/java/mage/util/TournamentUtil.java @@ -61,10 +61,9 @@ public class TournamentUtil { if (landSetCodes.isEmpty()) { // if sets have no basic lands and also it has no parent or parent has no lands get last set with lands // select a set with basic lands by random - Random generator = new Random(); List basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate(); if (basicLandSets.size() > 0) { - landSetCodes.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode()); + landSetCodes.add(basicLandSets.get(RandomUtil.nextInt(basicLandSets.size())).getCode()); } } @@ -75,7 +74,6 @@ public class TournamentUtil { } public static List getLands(String landName, int number, Set landSets) { - Random random = new Random(); CardCriteria criteria = new CardCriteria(); if (!landSets.isEmpty()) { criteria.setCodes(landSets.toArray(new String[landSets.size()])); @@ -85,7 +83,7 @@ public class TournamentUtil { List cards = new ArrayList<>(); if (!lands.isEmpty()) { for (int i = 0; i < number; i++) { - Card land = lands.get(random.nextInt(lands.size())).getCard(); + Card land = lands.get(RandomUtil.nextInt(lands.size())).getCard(); cards.add(land); } }