Added seeds support to random util:

* all xmage code uses shared util to generate random values;
 * tests can uses seeds to repeat "random" results like deck builds or AI plays;
This commit is contained in:
Oleg Agafonov 2018-12-30 03:52:30 +04:00
parent 52df594396
commit 2ebad63595
13 changed files with 415 additions and 265 deletions

View file

@ -1,33 +1,38 @@
package mage.util;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by IGOUDT on 5-9-2016.
*/
public final class RandomUtil {
private static Random random = new Random(); // thread safe with seed support
private RandomUtil() {
}
public static Random getRandom() {
return ThreadLocalRandom.current();
return random;
}
public static int nextInt() {
return ThreadLocalRandom.current().nextInt();
return random.nextInt();
}
public static int nextInt(int max) {
return ThreadLocalRandom.current().nextInt(max);
return random.nextInt(max);
}
public static boolean nextBoolean() {
return ThreadLocalRandom.current().nextBoolean();
return random.nextBoolean();
}
public static double nextDouble() {
return ThreadLocalRandom.current().nextDouble();
return random.nextDouble();
}
public static void setSeed(long newSeed) {
random.setSeed(newSeed);
}
}