PandaLib/src/main/java/fr/pandacube/java/util/RandomUtil.java

27 lines
608 B
Java
Raw Normal View History

package fr.pandacube.java.util;
2018-07-21 17:57:44 +02:00
import java.util.List;
import java.util.Random;
public class RandomUtil {
public static Random rand = new Random();
public static int nextIntBetween(int minInclu, int maxExclu) {
return rand.nextInt(maxExclu - minInclu) + minInclu;
}
public static double nextDoubleBetween(double minInclu, double maxExclu) {
return rand.nextDouble() * (maxExclu - minInclu) + minInclu;
}
2018-07-21 17:57:44 +02:00
public static <T> T arrayElement(T[] arr) {
return arr[rand.nextInt(arr.length)];
}
public static <T> T listElement(List<T> arr) {
return arr.get(rand.nextInt(arr.size()));
}
}