forked from External/mage
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:
parent
52df594396
commit
2ebad63595
13 changed files with 415 additions and 265 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue