mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
refactor : removed all instances of new Random() and replaced with RandomUtil for a ThreadLocal randomizer
This commit is contained in:
parent
f2cc8d4571
commit
e2a479255a
51 changed files with 173 additions and 133 deletions
|
@ -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<Character> 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<CardInfo> cardPool = CardRepository.instance.findCards(criteria);
|
||||
int retrievedCount = cardPool.size();
|
||||
List<DeckGeneratorCMC.CMC> 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<Card> 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<String, List<CardInfo>> basicLands) {
|
||||
Random random = new Random();
|
||||
String landName = DeckGeneratorPool.getBasicLandName(color.toString());
|
||||
List<CardInfo> basicLandsInfo = basicLands.get(landName);
|
||||
return basicLandsInfo.get(random.nextInt(basicLandsInfo.size() - 1)).getMockCard().copy();
|
||||
return basicLandsInfo.get(RandomUtil.nextInt(basicLandsInfo.size() - 1)).getMockCard().copy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Card> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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<CardInfo> 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);
|
||||
|
|
|
@ -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<String> actionCache;
|
||||
private static final List<TreeOptimizer> 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);
|
||||
|
|
|
@ -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<ColoredManaSymbol> 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<String> 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<UUID> 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) {
|
||||
|
|
|
@ -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<Ability> 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<Permanent> 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<Permanent> 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<UUID> 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<UUID> 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<UUID> 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<UUID> 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<? extends Card> pile1, List<? extends Card> 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<String> 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<String, String> 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<TriggeredAbility> 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<Permanent> 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<Permanent> blockers, CombatGroup combatGroup, List<UUID> 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);
|
||||
}
|
||||
|
|
|
@ -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<Card> 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);
|
||||
|
|
|
@ -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<Card> booster) {
|
||||
for (int i = 0; i < numBoosterDoubleFaced; i++) {
|
||||
List<CardInfo> 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<Card> booster, int number) {
|
||||
// number is here always 1
|
||||
List<CardInfo> doubleFacedCards;
|
||||
if (rnd.nextInt(8) > 0) {
|
||||
if (RandomUtil.nextInt(8) > 0) {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.RARE);
|
||||
} else {
|
||||
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.MYTHIC);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<UUID> 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()));
|
||||
|
|
|
@ -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<UUID> 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()));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.sets.eldritchmoon;
|
||||
|
||||
import mage.sets.EldritchMoon;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)."));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<UUID> 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<UUID> it = possibleTargets.iterator();
|
||||
while (i < rnd) {
|
||||
it.next();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<UUID> 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<UUID> 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
|
||||
|
|
|
@ -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<Card> booster, List<CardInfo> 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<CardInfo> specialLands = getSpecialLand();
|
||||
List<CardInfo> 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<CardInfo> rares = getCardsByRarity(Rarity.RARE);
|
||||
List<CardInfo> 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;
|
||||
}
|
||||
|
|
|
@ -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<String, ExpansionSet> {
|
|||
|
||||
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<String, ExpansionSet> {
|
|||
int tries = 0;
|
||||
List<Card> 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);
|
||||
|
|
|
@ -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<CardInfo> 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) {
|
||||
|
|
|
@ -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<CardInfo, Object> cardDao;
|
||||
private Set<String> classNames;
|
||||
|
||||
|
@ -317,7 +317,7 @@ public enum CardRepository {
|
|||
public CardInfo findCard(String name) {
|
||||
List<CardInfo> cards = findCards(name);
|
||||
if (!cards.isEmpty()) {
|
||||
return cards.get(random.nextInt(cards.size()));
|
||||
return cards.get(RandomUtil.nextInt(cards.size()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -121,6 +121,7 @@ public abstract class DraftImpl implements Draft {
|
|||
for(UUID playerId : players.keySet()) {
|
||||
table.add(playerId);
|
||||
}
|
||||
|
||||
table.setCurrent(currentId);
|
||||
}
|
||||
if (oldDraftPlayer.isPicking()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Round> rounds = new CopyOnWriteArrayList<>();
|
||||
protected Map<UUID, TournamentPlayer> 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<TournamentPlayer> roundPlayers, List<TournamentPlayer> 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
|
||||
|
|
|
@ -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<UUID> 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;
|
||||
|
|
|
@ -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<UUID> appliedEffects) {
|
||||
boolean result = rnd.nextBoolean();
|
||||
boolean result = RandomUtil.nextBoolean();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("[Flip a coin] " + getLogName() + (result ? " won (head)." : " lost (tail)."));
|
||||
}
|
||||
|
|
|
@ -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<UUID> 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();
|
||||
|
|
28
Mage/src/main/java/mage/util/RandomUtil.java
Normal file
28
Mage/src/main/java/mage/util/RandomUtil.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<ExpansionInfo> 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<Card> getLands(String landName, int number, Set<String> 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<Card> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue