Fixing some weird randomness issue of java.util.Random
This commit is contained in:
@@ -99,7 +99,7 @@ public class DraftChoiceBuilder {
|
|||||||
private List<CardCollection.Item> getCards(long seed, int stage) {
|
private List<CardCollection.Item> getCards(long seed, int stage) {
|
||||||
Random rnd = getRandom(seed, stage);
|
Random rnd = getRandom(seed, stage);
|
||||||
// Fixing some weird issue with Random
|
// Fixing some weird issue with Random
|
||||||
float thisFixesRandomnessForSomeReason = rnd.nextFloat();
|
float thisFixesRandomnessForSomeReason = rnd.nextInt();
|
||||||
final List<CardCollection.Item> cards = new ArrayList<CardCollection.Item>(possibleCards);
|
final List<CardCollection.Item> cards = new ArrayList<CardCollection.Item>(possibleCards);
|
||||||
Collections.shuffle(cards, rnd);
|
Collections.shuffle(cards, rnd);
|
||||||
return cards;
|
return cards;
|
||||||
|
|||||||
@@ -10,15 +10,12 @@ import com.gempukku.lotro.game.formats.LotroFormatLibrary;
|
|||||||
import com.gempukku.lotro.game.packs.SetDefinition;
|
import com.gempukku.lotro.game.packs.SetDefinition;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class HobbitDraftTest {
|
public class HobbitDraftTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
testRandomness();
|
|
||||||
|
|
||||||
LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
|
LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
|
||||||
final String property = System.getProperty("user.dir");
|
final String property = System.getProperty("user.dir");
|
||||||
String projectRoot = new File(property).getAbsolutePath();
|
String projectRoot = new File(property).getAbsolutePath();
|
||||||
@@ -38,20 +35,17 @@ public class HobbitDraftTest {
|
|||||||
final int playerId = 1000;
|
final int playerId = 1000;
|
||||||
|
|
||||||
Map<String, Integer> availableCards = new TreeMap<>(
|
Map<String, Integer> availableCards = new TreeMap<>(
|
||||||
new Comparator<String>() {
|
(o1, o2) -> {
|
||||||
@Override
|
int set1 = Integer.parseInt(o1.substring(0, o1.indexOf('_')));
|
||||||
public int compare(String o1, String o2) {
|
int set2 = Integer.parseInt(o2.substring(0, o2.indexOf('_')));
|
||||||
int set1 = Integer.parseInt(o1.substring(0, o1.indexOf('_')));
|
if (set1 != set2)
|
||||||
int set2 = Integer.parseInt(o2.substring(0, o2.indexOf('_')));
|
return set1 - set2;
|
||||||
if (set1 != set2)
|
int card1 = Integer.parseInt(o1.substring(o1.indexOf('_') + 1));
|
||||||
return set1 - set2;
|
int card2 = Integer.parseInt(o2.substring(o2.indexOf('_') + 1));
|
||||||
int card1 = Integer.parseInt(o1.substring(o1.indexOf('_') + 1));
|
return card1 - card2;
|
||||||
int card2 = Integer.parseInt(o2.substring(o2.indexOf('_') + 1));
|
|
||||||
return card1 - card2;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
// Take an example seed
|
// Take an example seed
|
||||||
long seed = getSeed(String.valueOf(collectionType + i), playerId);
|
long seed = getSeed(String.valueOf(collectionType + i), playerId);
|
||||||
|
|
||||||
@@ -78,6 +72,25 @@ public class HobbitDraftTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void testRandomness2() {
|
||||||
|
int lastValue = -1;
|
||||||
|
long patchStart = 1813024350;
|
||||||
|
long longestPatch = 0;
|
||||||
|
for (long seed = 0; seed < 8813024350L; seed++) {
|
||||||
|
final int value = new Random(seed).nextInt(8);
|
||||||
|
if (value != lastValue) {
|
||||||
|
long patchLength = seed - patchStart;
|
||||||
|
if (patchLength > longestPatch) {
|
||||||
|
System.out.println("Longest patch: " + patchStart + "-" + (seed - 1));
|
||||||
|
System.out.println("Patch length: " + patchLength);
|
||||||
|
longestPatch = patchLength;
|
||||||
|
}
|
||||||
|
patchStart = seed;
|
||||||
|
lastValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void testRandomness() {
|
private static void testRandomness() {
|
||||||
doRandomTest(4, false);
|
doRandomTest(4, false);
|
||||||
System.out.println("WTF!!!!");
|
System.out.println("WTF!!!!");
|
||||||
|
|||||||
Reference in New Issue
Block a user