Package openbook.util
Class Randomizer
- java.lang.Object
-
- openbook.util.Randomizer
-
public class Randomizer extends java.lang.ObjectA set of static utility functions for simulating pseudo-randomness.- Author:
- Pinaki Poddar
-
-
Constructor Summary
Constructors Constructor Description Randomizer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanprobability(double p)Returns true with a probability of p.static doublerandom(double min, double max)static intrandom(int n)Picks a random number between 0 (inclusive) and N (exclusive).static intrandom(int min, int max)Picks a uniformly distributed random integer within the given range.static java.lang.StringrandomString(int... segments)Generates a random alphanumeric String with each segment separated by a dash.static <T> TselectRandom(java.util.List<T> list)Picks a random element from the given list.static <T> java.util.List<T>selectRandom(java.util.List<T> list, int n)Selects n elements randomly from the given list.
-
-
-
Method Detail
-
probability
public static boolean probability(double p)
Returns true with a probability of p.
-
random
public static int random(int n)
Picks a random number between 0 (inclusive) and N (exclusive).
-
random
public static int random(int min, int max)Picks a uniformly distributed random integer within the given range.
-
random
public static double random(double min, double max)
-
randomString
public static java.lang.String randomString(int... segments)
Generates a random alphanumeric String with each segment separated by a dash.
-
selectRandom
public static <T> T selectRandom(java.util.List<T> list)
Picks a random element from the given list.
-
selectRandom
public static <T> java.util.List<T> selectRandom(java.util.List<T> list, int n)Selects n elements randomly from the given list.
-
-