Java Utililty Methods Random

List of utility methods to do Random

Description

The list of methods to do Random are organized into topic(s).

Method

charrandomDigit()
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);
TrandomElement(List list, Random random)
random Element
if (list.isEmpty())
    throw new IndexOutOfBoundsException("List is empty");
return list.get(random.nextInt(list.size()));
TrandomElement(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)];
TrandomElementFromArray(T[] source)
random Element From Array
return source[(int) (Math.random() * source.length)];
intrandomEntre1eh100()
random Entreeh
return (int) (Math.random() * 100) + 1;
TrandomEnum(Class clazz)
Gets a random enum value from an enum.
return clazz.getEnumConstants()[RANDOM.nextInt(clazz.getEnumConstants().length)];
booleanrandomEvent(float theChance, float theRange)
random Event
return Math.random() < (theChance / (theRange + 1.0f));
voidrandomException()
random Exception
if ((long) Math.abs(Math.random() * 1000) % 57 == 0) {
    throw new RuntimeException("Random Exception Raised");
booleanrandomFailure()
random Failure
return !randomSuccess();