forked from External/mage
* changing goad to designation, refactored goad effects to be continuous * [AFC] Implemented Vengeful Ancestor * reworked effects which goad an attached creature * updated goading implementation * updated combat with new goad logic * some more changes, added a test * another fix * update to test, still fails * added more failing tests * more failing tests * added additional goad check * small fix to two tests (still failing * added a regular combat test (passes and fails randomly) * fixed bug in computer player random selection * some changes to how TargetDefender is handled * removed unnecessary class * more combat fixes, tests pass now * removed tests which no longer work due to combat changes * small merge fix * [NEC] Implemented Komainu Battle Armor * [NEC] Implemented Kaima, the Fractured Calm * [NEC] added all variants
61 lines
1.4 KiB
Java
61 lines
1.4 KiB
Java
package mage.util;
|
|
|
|
import java.awt.*;
|
|
import java.util.Collection;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* Created by IGOUDT on 5-9-2016.
|
|
*/
|
|
public final class RandomUtil {
|
|
|
|
private static final Random random = new Random(); // thread safe with seed support
|
|
|
|
private RandomUtil() {
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public static double nextDouble() {
|
|
return random.nextDouble();
|
|
}
|
|
|
|
public static Color nextColor() {
|
|
return new Color(RandomUtil.nextInt(256), RandomUtil.nextInt(256), RandomUtil.nextInt(256));
|
|
}
|
|
|
|
public static void setSeed(long newSeed) {
|
|
random.setSeed(newSeed);
|
|
}
|
|
|
|
public static <T> T randomFromCollection(Collection<T> collection) {
|
|
if (collection.size() < 2) {
|
|
return collection.stream().findFirst().orElse(null);
|
|
}
|
|
int rand = nextInt(collection.size());
|
|
int count = 0;
|
|
for (T current : collection) {
|
|
if (count == rand) {
|
|
return current;
|
|
}
|
|
count++;
|
|
}
|
|
return null;
|
|
}
|
|
}
|