List of utility methods to do Random
char | randomDigit() choose a random digit return ((char) ('0' + randomInt(10))); |
double[] | randomDoubleArray(int size) random Double Array Random rand = new Random(System.currentTimeMillis()); return randomDoubleArray(size, rand); |
T | randomElement(List extends T> list, Random random) random Element if (list.isEmpty()) throw new IndexOutOfBoundsException("List is empty"); return list.get(random.nextInt(list.size())); |
T | randomElement(T[] items) choose a random element from an array switch (items.length) { case 0: return null; case 1: return items[0]; default: return items[RND.nextInt(items.length)]; |
T | randomElementFromArray(T[] source) random Element From Array return source[(int) (Math.random() * source.length)]; |
int | randomEntre1eh100() random Entreeh return (int) (Math.random() * 100) + 1; |
T | randomEnum(Class Gets a random enum value from an enum. return clazz.getEnumConstants()[RANDOM.nextInt(clazz.getEnumConstants().length)];
|
boolean | randomEvent(float theChance, float theRange) random Event return Math.random() < (theChance / (theRange + 1.0f));
|
void | randomException() random Exception if ((long) Math.abs(Math.random() * 1000) % 57 == 0) { throw new RuntimeException("Random Exception Raised"); |
boolean | randomFailure() random Failure return !randomSuccess();
|