Update lots of code to use MyRandom directly.

Some parts of the code were using the normal random, instead of going through the MyRandom class. This makes it much harder to change the RNG method later. For example, you may want to change the RNG to always be seeded with the same number, for running AI experiments. This change makes that easier.
This commit is contained in:
Meerkov
2018-04-16 21:26:12 -07:00
parent 645d70e6ce
commit 5c9a27c930
21 changed files with 81 additions and 102 deletions

View File

@@ -26,6 +26,8 @@ import forge.deck.CardPool;
import forge.deck.DeckFormat;
import forge.item.PaperCard;
import forge.util.MyRandom;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.util.Arrays;
@@ -85,13 +87,13 @@ public class DeckGenerator2Color extends DeckGeneratorBase {
format0.adjustCMCLevels(cmcLevels);
if( c1 == 0 && c2 == 0) {
int color1 = r.nextInt(5);
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
int color1 = MyRandom.getRandom().nextInt(5);
int color2 = (color1 + 1 + MyRandom.getRandom().nextInt(4)) % 5;
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2);
} else if ( c1 == 0 || c2 == 0 ) {
byte knownColor = (byte) (c1 | c2);
int color1 = Arrays.binarySearch(MagicColor.WUBRG, knownColor);
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
int color2 = (color1 + 1 + MyRandom.getRandom().nextInt(4)) % 5;
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2);
} else {
colors = ColorSet.fromMask(c1 | c2);

View File

@@ -87,8 +87,8 @@ public class DeckGenerator3Color extends DeckGeneratorBase {
return;
case 0:
int color1 = r.nextInt(5);
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
int color1 = MyRandom.getRandom().nextInt(5);
int color2 = (color1 + 1 + MyRandom.getRandom().nextInt(4)) % 5;
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2).inverse();
return;

View File

@@ -86,8 +86,8 @@ public class DeckGenerator4Color extends DeckGeneratorBase {
return;
case 0:
int color1 = r.nextInt(5);
int color2 = (color1 + 1 + r.nextInt(4)) % 5;
int color1 = MyRandom.getRandom().nextInt(5);
int color2 = (color1 + 1 + MyRandom.getRandom().nextInt(4)) % 5;
colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2).inverse();
return;

View File

@@ -51,7 +51,6 @@ import java.util.regex.Pattern;
*/
public abstract class DeckGeneratorBase {
protected final DebugTrace trace = new DebugTrace();
protected final Random r = MyRandom.getRandom();
protected final Map<String, Integer> cardCounts = new HashMap<String, Integer>();
protected int maxDuplicates = 4;
protected boolean useArtifacts = true;
@@ -133,7 +132,7 @@ public abstract class DeckGeneratorBase {
int res = 0;
while (res < cnt) {
PaperCard cp = source.get(r.nextInt(srcLen));
PaperCard cp = source.get(MyRandom.getRandom().nextInt(srcLen));
int newCount = cardCounts.get(cp.getName()) + 1;
//add card to deck if not already maxed out on card
@@ -166,7 +165,7 @@ public abstract class DeckGeneratorBase {
int res = 0;
while (res < cnt) {
String s = source.get(r.nextInt(srcLen));
String s = source.get(MyRandom.getRandom().nextInt(srcLen));
int newCount = cardCounts.get(s) + 1;
//add card to deck if not already maxed out on card

View File

@@ -26,6 +26,8 @@ import forge.deck.CardPool;
import forge.deck.DeckFormat;
import forge.item.PaperCard;
import forge.util.MyRandom;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.util.List;
@@ -79,7 +81,7 @@ public class DeckGeneratorMonoColor extends DeckGeneratorBase {
public void initialize(final String clr1){
if (MagicColor.fromName(clr1) == 0) {
int color1 = r.nextInt(5);
int color1 = MyRandom.getRandom().nextInt(5);
colors = ColorSet.fromMask(MagicColor.WHITE << color1);
} else {
colors = ColorSet.fromNames(clr1);

View File

@@ -83,7 +83,6 @@ public class BoosterGenerator {
&& edition.getFoilType() != FoilType.NOT_SUPPORTED;
boolean foilAtEndOfPack = hasFoil && edition.getFoilAlwaysInCommonSlot();
Random rand = new Random();
// Foil chances
// 1 Rare or Mythic rare (distribution ratio same as nonfoils)
// 2-3 Uncommons
@@ -96,7 +95,7 @@ public class BoosterGenerator {
// Other special types of foil slots, add here
CardRarity foilCard = CardRarity.Unknown;
while (foilCard == CardRarity.Unknown) {
int randomNum = rand.nextInt(10) + 1;
int randomNum = MyRandom.getRandom().nextInt(10) + 1;
switch (randomNum) {
case 1:
// Rare or Mythic
@@ -126,7 +125,7 @@ public class BoosterGenerator {
if (edition.getName().equals("Vintage Masters")) {
// 1 in 53 packs, with 7 possibilities for the slot itself in VMA
// (1 RareMythic, 2 Uncommon, 3 Common, 1 Special)
if (rand.nextInt(53) <= 7) {
if (MyRandom.getRandom().nextInt(53) <= 7) {
foilCard = CardRarity.Special;
}
}
@@ -147,7 +146,7 @@ public class BoosterGenerator {
// so 3 out of the 53 rares in the set.
// while information cannot be found, my personal (subjective) experience from that time was
// that they were indeed similar chance, at least not significantly less.
if (rand.nextInt(53) <= 3) {
if (MyRandom.getRandom().nextInt(53) <= 3) {
foilCard = CardRarity.Special;
}
}
@@ -200,7 +199,7 @@ public class BoosterGenerator {
// According to information I found, Basic Lands
// are on the common foil sheet, each type appearing once.
// Large Sets usually have 110 commons and 20 lands.
if (rand.nextInt(130) <= 20) {
if (MyRandom.getRandom().nextInt(130) <= 20) {
foilSlot = BoosterSlots.BASIC_LAND;
}
}
@@ -307,7 +306,7 @@ public class BoosterGenerator {
// 1 out of ~30 normal and mythic rares are foil,
// match that.
// If not special card, make it always foil.
if ((rand.nextInt(30) == 1) || (foilSlot != BoosterSlots.SPECIAL)) {
if ((MyRandom.getRandom().nextInt(30) == 1) || (foilSlot != BoosterSlots.SPECIAL)) {
foilCardGeneratedAndHeld.add(generateFoilCard(ps));
} else {
// Otherwise it's not foil (even though this is the

View File

@@ -101,21 +101,20 @@ public class Aggregates {
public static final <T> T random(final Iterable<T> source) {
if (source == null) { return null; }
Random rnd = MyRandom.getRandom();
if (source instanceof List<?>) {
List<T> src = (List<T>)source;
int len = src.size();
switch(len) {
case 0: return null;
case 1: return src.get(0);
default: return src.get(rnd.nextInt(len));
default: return src.get(MyRandom.getRandom().nextInt(len));
}
}
T candidate = null;
int lowest = Integer.MAX_VALUE;
for (final T item : source) {
int next = rnd.nextInt();
int next = MyRandom.getRandom().nextInt();
if(next < lowest) {
lowest = next;
candidate = item;
@@ -129,7 +128,6 @@ public class Aggregates {
}
public static final <T, L extends List<T>> L random(final Iterable<T> source, final int count, final L list) {
// Using Reservoir Sampling to grab X random values from source
Random rnd = MyRandom.getRandom();
int i = 0;
for (T item : source) {
i++;
@@ -138,7 +136,7 @@ public class Aggregates {
list.add(item);
} else {
// Progressively reduce odds of item > count to get added into the reservoir
int j = rnd.nextInt(i);
int j = MyRandom.getRandom().nextInt(i);
if (j < count) {
list.set(j, item);
}
@@ -161,8 +159,7 @@ public class Aggregates {
}
public static int randomInt(int min, int max) {
Random rnd = MyRandom.getRandom();
return rnd.nextInt(max - min + 1) + min;
return MyRandom.getRandom().nextInt(max - min + 1) + min;
}
public static final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Function<U, K> fnUniqueKey) { // this might be exotic

View File

@@ -6,7 +6,6 @@ import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* @author Marc
@@ -202,8 +201,8 @@ public final class NameGenerator {
/** Generates a single name that doesn't match the specified name.
*
* @param gender String specifying the desired gender. Recognises "Male", "Female" and "Any".
* @param type String specifying the desired type. Recognises "Fantasy", "Generic" and "Any".
* @param gender String specifying the desired gender. Recognizes "Male", "Female" and "Any".
* @param type String specifying the desired type. Recognizes "Fantasy", "Generic" and "Any".
* @param excludeNames A list of names already being used.
* @return Returns the generated name string.
*/
@@ -211,33 +210,32 @@ public final class NameGenerator {
usedNames = excludeNames;
String name = "";
Random seed = MyRandom.getRandom();
boolean useMoniker = false;
switch (type + gender) {
case "GenericMale": { sourceList = genericMales; useMoniker = seed.nextFloat() <= 0.03f; break;}
case "GenericFemale": { sourceList = genericFemales; useMoniker = seed.nextFloat() <= 0.02f; break;}
case "FantasyMale": { sourceList = fantasyMales; useMoniker = seed.nextFloat() <= 0.10f; break;}
case "FantasyFemale": { sourceList = fantasyFemales; useMoniker = seed.nextFloat() <= 0.08f; break;}
case "GenericMale": { sourceList = genericMales; useMoniker = MyRandom.getRandom().nextFloat() <= 0.03f; break;}
case "GenericFemale": { sourceList = genericFemales; useMoniker = MyRandom.getRandom().nextFloat() <= 0.02f; break;}
case "FantasyMale": { sourceList = fantasyMales; useMoniker = MyRandom.getRandom().nextFloat() <= 0.10f; break;}
case "FantasyFemale": { sourceList = fantasyFemales; useMoniker = MyRandom.getRandom().nextFloat() <= 0.08f; break;}
case "AnyMale":
sourceList = getCombinedLists(genericMales, fantasyMales);
useMoniker = seed.nextFloat() <= 0.06f;
useMoniker = MyRandom.getRandom().nextFloat() <= 0.06f;
break;
case "AnyFemale":
sourceList = getCombinedLists(genericFemales, fantasyFemales);
useMoniker = seed.nextFloat() <= 0.025f;
useMoniker = MyRandom.getRandom().nextFloat() <= 0.025f;
break;
case "GenericAny":
sourceList = getCombinedLists(genericMales, genericFemales);
useMoniker = seed.nextFloat() <= 0.015f;
useMoniker = MyRandom.getRandom().nextFloat() <= 0.015f;
break;
case "FantasyAny":
sourceList = getCombinedLists(fantasyMales, fantasyFemales);
useMoniker = seed.nextFloat() <= 0.06f;
useMoniker = MyRandom.getRandom().nextFloat() <= 0.06f;
break;
default:
@@ -248,12 +246,12 @@ public final class NameGenerator {
Collections.addAll(all, genericFemales);
Collections.addAll(all, fantasyFemales);
sourceList = all.toArray(new String[all.size()]);
useMoniker = seed.nextFloat() <= 0.04f;
useMoniker = MyRandom.getRandom().nextFloat() <= 0.04f;
break;
}
do {
name = sourceList[seed.nextInt(sourceList.length)];
name = sourceList[MyRandom.getRandom().nextInt(sourceList.length)];
} while (excludeNames.contains(name));
usedNames.add(name); // add base name to used names list
@@ -261,7 +259,7 @@ public final class NameGenerator {
if (useMoniker) {
String moniker = "";
do {
moniker = monikers[seed.nextInt(monikers.length)];
moniker = monikers[MyRandom.getRandom().nextInt(monikers.length)];
} while (usedMonikers.contains(moniker));
usedMonikers.add(moniker);

View File

@@ -50,6 +50,7 @@ import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.trackable.Tracker;
import forge.util.Aggregates;
import forge.util.MyRandom;
import forge.util.Visitor;
import java.util.*;
@@ -797,7 +798,7 @@ public class Game {
onePlayerHasTimeShifted = false;
}
CardRarity anteRarity = validRarities.get(new Random().nextInt(validRarities.size()));
CardRarity anteRarity = validRarities.get(MyRandom.getRandom().nextInt(validRarities.size()));
System.out.println("Rarity chosen for ante: " + anteRarity.name());
@@ -827,7 +828,7 @@ public class Game {
library.removeAll((Collection<?>)toRemove);
if (library.size() > 0) { //Make sure that matches were found. If not, use the original method to choose antes
Card ante = library.get(new Random().nextInt(library.size()));
Card ante = library.get(MyRandom.getRandom().nextInt(library.size()));
anteed.put(player, ante);
} else {
chooseRandomCardsForAnte(player, anteed);

View File

@@ -179,7 +179,7 @@ public class Match {
return myRemovedAnteCards;
}
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool section, boolean canRandomFoil, Random generator) {
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool section, boolean canRandomFoil) {
PlayerZone library = player.getZone(zoneType);
List<Card> newLibrary = new ArrayList<Card>();
for (final Entry<PaperCard, Integer> stackOfCards : section) {
@@ -245,11 +245,9 @@ public class Match {
}
}
Random generator = MyRandom.getRandom();
preparePlayerLibrary(player, ZoneType.Library, myDeck.getMain(), psc.useRandomFoil(), generator);
preparePlayerLibrary(player, ZoneType.Library, myDeck.getMain(), psc.useRandomFoil());
if (myDeck.has(DeckSection.Sideboard)) {
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), psc.useRandomFoil(), generator);
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), psc.useRandomFoil());
}
player.initVariantsZones(psc);

View File

@@ -9,11 +9,11 @@ import forge.game.player.Player;
import forge.game.spellability.AbilitySub;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions;
import forge.util.MyRandom;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
public class ChooseNumberEffect extends SpellAbilityEffect {
@@ -54,8 +54,7 @@ public class ChooseNumberEffect extends SpellAbilityEffect {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
int chosen;
if (random) {
final Random randomGen = new Random();
chosen = randomGen.nextInt(max - min) + min;
chosen = MyRandom.getRandom().nextInt(max - min) + min;
p.getGame().getAction().nofityOfValue(sa, p, Integer.toString(chosen), null);
} else {
String title = sa.hasParam("ListTitle") ? sa.getParam("ListTitle") : "Choose a number";

View File

@@ -179,8 +179,7 @@ public class DigUntilEffect extends SpellAbilityEffect {
}
}
if (sa.hasParam("RevealRandomOrder")) {
final Random random = MyRandom.getRandom();
Collections.shuffle(revealed, random);
Collections.shuffle(revealed, MyRandom.getRandom());
}
if (sa.hasParam("NoneFoundDestination") && found.size() < untilAmount) {

View File

@@ -11,7 +11,6 @@ import forge.util.MyRandom;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ReorderZoneEffect extends SpellAbilityEffect {
@Override
@@ -33,8 +32,7 @@ public class ReorderZoneEffect extends SpellAbilityEffect {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
CardCollection list = new CardCollection(p.getCardsIn(zone));
if (shuffle) {
final Random ran = MyRandom.getRandom();
Collections.shuffle(list, ran);
Collections.shuffle(list, MyRandom.getRandom());
p.getZone(zone).setCards(list);
}
else {

View File

@@ -27,7 +27,6 @@ import forge.util.MyRandom;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* <p>
@@ -120,7 +119,6 @@ public class DeckGeneratorTheme extends DeckGeneratorBase {
final List<Grp> groups = readGroups(lines);
// begin assigning cards to the deck
final Random r = MyRandom.getRandom();
for (int i = 0; i < groups.size(); i++) {
final Grp g = groups.get(i);
@@ -130,14 +128,14 @@ public class DeckGeneratorTheme extends DeckGeneratorBase {
errorBuilder.append("Group" + i + ":" + grpCnt + "\n");
for (int j = 0; j < grpCnt; j++) {
s = g.cardnames.get(r.nextInt(cnSize));
s = g.cardnames.get(MyRandom.getRandom().nextInt(cnSize));
ss = s.split("\\|");
int lc = 0;
while ((cardCounts.get(ss[0]) >= g.maxCnt) || (lc > 999)) {
// looping
// forever
s = g.cardnames.get(r.nextInt(cnSize));
s = g.cardnames.get(MyRandom.getRandom().nextInt(cnSize));
ss = s.split("\\|");
lc++;
}

View File

@@ -43,10 +43,9 @@ import java.util.*;
public class DeckgenUtil {
public static Deck buildCardGenDeck(GameFormat format, boolean isForAI){
Random random = new Random();
try {
List<String> keys = new ArrayList<>(CardRelationMatrixGenerator.cardPools.get(format.getName()).keySet());
String randomKey = keys.get( random.nextInt(keys.size()) );
String randomKey = keys.get( MyRandom.getRandom().nextInt(keys.size()) );
Predicate<PaperCard> cardFilter = Predicates.and(format.getFilterPrinted(),PaperCard.Predicates.name(randomKey));
PaperCard keyCard = FModel.getMagicDb().getCommonCards().getAllCards(cardFilter).get(0);
@@ -124,7 +123,6 @@ public class DeckgenUtil {
Collections.sort(potentialCards,new CardDistanceComparator());
Collections.reverse(potentialCards);
//get second keycard
Random r = new Random();
List<PaperCard> preSelectedCards = new ArrayList<>();
for(Map.Entry<PaperCard,Integer> pair:potentialCards){
preSelectedCards.add(pair.getKey());
@@ -146,7 +144,7 @@ public class DeckgenUtil {
if(preSelectedCards.size()<randMax){
randMax=preSelectedCards.size();
}
PaperCard secondKeycard = preSelectedCards.get(r.nextInt(randMax));
PaperCard secondKeycard = preSelectedCards.get(MyRandom.getRandom().nextInt(randMax));
List<Map.Entry<PaperCard,Integer>> potentialSecondCards = CardRelationMatrixGenerator.cardPools.get(format.getName()).get(secondKeycard.getName());
//combine card distances from second key card and re-sort
@@ -166,7 +164,7 @@ public class DeckgenUtil {
int removeCount=0;
int i=0;
for(PaperCard c:selectedCards){
if(r.nextInt(100)>70+(15-(i/selectedCards.size())*selectedCards.size()) && removeCount<4 //randomly remove some cards - more likely as distance increases
if(MyRandom.getRandom().nextInt(100)>70+(15-(i/selectedCards.size())*selectedCards.size()) && removeCount<4 //randomly remove some cards - more likely as distance increases
&&!c.getName().contains("Urza")){ //avoid breaking Tron decks
toRemove.add(c);
removeCount++;
@@ -184,9 +182,9 @@ public class DeckgenUtil {
List<PaperCard> playsetList = new ArrayList<>();
int keyCardCount=4;
if(card.getRules().getMainPart().getManaCost().getCMC()>7){
keyCardCount=1+r.nextInt(4);
keyCardCount=1+MyRandom.getRandom().nextInt(4);
}else if(card.getRules().getMainPart().getManaCost().getCMC()>5){
keyCardCount=2+r.nextInt(3);
keyCardCount=2+MyRandom.getRandom().nextInt(3);
}
for(int j=0;j<keyCardCount;++j) {
playsetList.add(card);
@@ -194,16 +192,16 @@ public class DeckgenUtil {
//Add 2nd keycard
int keyCard2Count=4;
if(card.getRules().getMainPart().getManaCost().getCMC()>7){
keyCard2Count=1+r.nextInt(4);
keyCard2Count=1+MyRandom.getRandom().nextInt(4);
}else if(card.getRules().getMainPart().getManaCost().getCMC()>5){
keyCard2Count=2+r.nextInt(3);
keyCard2Count=2+MyRandom.getRandom().nextInt(3);
}
for(int j=0;j<keyCard2Count;++j) {
playsetList.add(secondKeycard);
}
for (PaperCard c:selectedCards){
for(int j=0;j<4;++j) {
if(r.nextInt(100)<90) {
if(MyRandom.getRandom().nextInt(100)<90) {
playsetList.add(c);
}
}
@@ -525,7 +523,6 @@ public class DeckgenUtil {
}else {
potentialCards.addAll(CardRelationMatrixGenerator.cardPools.get(DeckFormat.Commander.toString()).get(commander.getName()));
}
Random r = new Random();
//Collections.shuffle(potentialCards, r);
List<PaperCard> preSelectedCards = new ArrayList<>();
for(Map.Entry<PaperCard,Integer> pair:potentialCards){
@@ -557,7 +554,7 @@ public class DeckgenUtil {
if(preSelectedCards.size()<75){
break;
}
if(r.nextInt(100)>60+(15-(i/preSelectedCards.size())*preSelectedCards.size()) && removeCount<4 //randomly remove some cards - more likely as distance increases
if(MyRandom.getRandom().nextInt(100)>60+(15-(i/preSelectedCards.size())*preSelectedCards.size()) && removeCount<4 //randomly remove some cards - more likely as distance increases
&&!c.getName().contains("Urza")&&!c.getName().contains("Wastes")){ //avoid breaking Tron decks
toRemove.add(c);
removeCount++;
@@ -578,7 +575,7 @@ public class DeckgenUtil {
colorList=colorListFiltered;
}
List<PaperCard> cardList = Lists.newArrayList(colorList);
Collections.shuffle(cardList, new Random());
Collections.shuffle(cardList, MyRandom.getRandom());
int shortlistlength=400;
if(cardList.size()<shortlistlength){
shortlistlength=cardList.size();

View File

@@ -514,7 +514,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
}
};
List<PaperCard> randomPool = Lists.newArrayList(pool.getAllCards(possibleFromFullPool));
Collections.shuffle(randomPool,new Random());
Collections.shuffle(randomPool, MyRandom.getRandom());
Iterator<PaperCard> iRandomPool=randomPool.iterator();
while (deckList.size() < targetSize) {
if (logToConsole) {
@@ -685,9 +685,9 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
if(colors.isColorless()){
minBasics=0;
}else if(colors.isMonoColor()){
minBasics=Math.round((r.nextInt(15)+9)*((float) targetSize) / 60);
minBasics=Math.round((MyRandom.getRandom().nextInt(15)+9)*((float) targetSize) / 60);
}else{
minBasics=Math.round((r.nextInt(8)+6)*((float) targetSize) / 60);
minBasics=Math.round((MyRandom.getRandom().nextInt(8)+6)*((float) targetSize) / 60);
}
@@ -706,7 +706,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
}
continue;
}
if (!inverseDLands.contains(card.getName())&&!dLands.contains(card.getName())&&r.nextInt(100)<90) {
if (!inverseDLands.contains(card.getName())&&!dLands.contains(card.getName())&&MyRandom.getRandom().nextInt(100)<90) {
landsToAdd.add(card);
landsNeeded--;
if (logToConsole) {
@@ -741,7 +741,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
}
};
List<PaperCard> randomPool = Lists.newArrayList(pool.getAllCards(possibleFromFullPool));
Collections.shuffle(randomPool,new Random());
Collections.shuffle(randomPool, MyRandom.getRandom());
Iterator<PaperCard> iRandomPool=randomPool.iterator();
for(int i=0;i<num;++i){
PaperCard randomCard=iRandomPool.next();
@@ -801,12 +801,12 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
rankedColorList.removeAll(keyCardList);
}*/
final Map<Integer,Integer> targetCMCs = new HashMap<>();
targetCMCs.put(1,Math.round((r.nextInt(4)+2)*targetSize/60));//2
targetCMCs.put(2,Math.round((r.nextInt(5)+5)*targetSize/60));//6
targetCMCs.put(3,Math.round((r.nextInt(5)+6)*targetSize/60));//7
targetCMCs.put(4,Math.round((r.nextInt(3)+3)*targetSize/60));//4
targetCMCs.put(5,Math.round((r.nextInt(3)+3)*targetSize/60));//3
targetCMCs.put(6,Math.round((r.nextInt(3)+1)*targetSize/60));//2
targetCMCs.put(1,Math.round((MyRandom.getRandom().nextInt(4)+2)*targetSize/60));//2
targetCMCs.put(2,Math.round((MyRandom.getRandom().nextInt(5)+5)*targetSize/60));//6
targetCMCs.put(3,Math.round((MyRandom.getRandom().nextInt(5)+6)*targetSize/60));//7
targetCMCs.put(4,Math.round((MyRandom.getRandom().nextInt(3)+3)*targetSize/60));//4
targetCMCs.put(5,Math.round((MyRandom.getRandom().nextInt(3)+3)*targetSize/60));//3
targetCMCs.put(6,Math.round((MyRandom.getRandom().nextInt(3)+1)*targetSize/60));//2
final Map<Integer, Integer> creatureCosts = new HashMap<Integer, Integer>();

View File

@@ -11,7 +11,6 @@ import forge.util.MyRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* Deck builder for Sealed Deck Format.
@@ -67,17 +66,16 @@ public class SealedDeckBuilder extends LimitedDeckBuilder {
String color1;
String color2;
final Random r = MyRandom.getRandom();
if (maxColors.size() > 1) {
int n = r.nextInt(maxColors.size());
int n = MyRandom.getRandom().nextInt(maxColors.size());
color1 = maxColors.get(n);
maxColors.remove(n);
n = r.nextInt(maxColors.size());
n = MyRandom.getRandom().nextInt(maxColors.size());
color2 = maxColors.get(n);
} else {
color1 = maxColors.get(0);
if (secondColors.size() > 1) {
color2 = secondColors.get(r.nextInt(secondColors.size()));
color2 = secondColors.get(MyRandom.getRandom().nextInt(secondColors.size()));
} else {
color2 = secondColors.get(0);
}

View File

@@ -26,7 +26,6 @@ import forge.util.gui.SGuiChoose;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* This type extends UnOpenedProduct to support booster choice or random boosters
@@ -43,7 +42,6 @@ public class UnOpenedMeta implements IUnOpenedProduct {
private final List<MetaSet> metaSets;
private final JoinOperation operation;
private final Random generator = MyRandom.getRandom();
/**
* Constructor for UnOpenedMeta.
@@ -104,7 +102,7 @@ public class UnOpenedMeta implements IUnOpenedProduct {
//$FALL-THROUGH$
case RandomOne: // AI should fall though here from the case above
int selected = generator.nextInt(metaSets.size());
int selected = MyRandom.getRandom().nextInt(metaSets.size());
final IUnOpenedProduct newBooster = metaSets.get(selected).getBooster();
return newBooster.get();

View File

@@ -23,6 +23,7 @@ import forge.quest.data.QuestPreferences.DifficultyPrefs;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.io.QuestDuelReader;
import forge.util.CollectionSuppliers;
import forge.util.MyRandom;
import forge.util.maps.EnumMapOfLists;
import forge.util.maps.MapOfLists;
import forge.util.storage.IStorage;
@@ -230,11 +231,9 @@ public class QuestEventDuelManager {
/** */
public void randomizeOpponents() {
final long seed = new Random().nextLong();
final Random r = new Random(seed);
for (QuestEventDifficulty qd : sortedDuels.keySet()) {
List<QuestEventDuel> list = (List<QuestEventDuel>) sortedDuels.get(qd);
Collections.shuffle(list, r);
Collections.shuffle(list, MyRandom.getRandom());
}
}

View File

@@ -25,7 +25,6 @@ import forge.util.MyRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
* <p>
@@ -73,7 +72,6 @@ public class ReadPriceList {
private Map<String, Integer> readFile(final String file) {
final Map<String, Integer> map = new HashMap<>();
final Random r = MyRandom.getRandom();
final List<String> lines = FileUtil.readFile(file);
for (final String line : lines) {
@@ -96,15 +94,15 @@ public class ReadPriceList {
if (!(MagicColor.Constant.BASIC_LANDS.contains(name) || MagicColor.Constant.SNOW_LANDS.contains(name)) && !ForgeConstants.PRICES_BOOSTER_FILE.equals(file)) {
float ff;
if (r.nextInt(100) < 90) {
ff = r.nextInt(10) * (float) .01;
if (MyRandom.getRandom().nextInt(100) < 90) {
ff = MyRandom.getRandom().nextInt(10) * (float) .01;
}
else {
// +/- 50%
ff = r.nextInt(50) * (float) .01;
ff = MyRandom.getRandom().nextInt(50) * (float) .01;
}
if (r.nextInt(100) < 50) {
if (MyRandom.getRandom().nextInt(100) < 50) {
val = (int) (val * (1 - ff));
} else {
// +ff%

View File

@@ -2,9 +2,9 @@ package forge.sound;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Random;
import forge.properties.ForgeConstants;
import forge.util.MyRandom;
public enum MusicPlaylist {
MENUS("menus/"),
@@ -13,7 +13,6 @@ public enum MusicPlaylist {
private final String subDir;
private int mostRecentTrackIdx = -1;
private String[] filenames;
private final Random randomGenerator = new Random();
private MusicPlaylist(String subDir0) {
subDir = subDir0;
@@ -44,7 +43,7 @@ public enum MusicPlaylist {
else { //determine filename randomly from playlist
int newIndex;
do {
newIndex = randomGenerator.nextInt(filenames.length);
newIndex = MyRandom.getRandom().nextInt(filenames.length);
} while (newIndex == mostRecentTrackIdx); //ensure a different track is chosen than the last one
mostRecentTrackIdx = newIndex;