Java Utililty Methods Random Enum

List of utility methods to do Random Enum

Description

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

Method

TRandomEnum(Class c)
Random Enum
return RandomEnum(c, 0);
TrandomEnum(Class c)
random Enum
Random random = new Random();
int r = random.nextInt(c.getEnumConstants().length);
return c.getEnumConstants()[r];
TrandomEnum(Class clazz)
Gets a random enum value from an enum.
return clazz.getEnumConstants()[RANDOM.nextInt(clazz.getEnumConstants().length)];
TrandomEnum(Class cls, T exceptValue)
random Enum
int x = new Random().nextInt(cls.getEnumConstants().length);
T t = cls.getEnumConstants()[x];
return t.equals(exceptValue) ? randomEnum(cls, exceptValue) : t;
SetrandomEnumSet(Class enumType)
random Enum Set
EnumSet<E> set = EnumSet.noneOf(enumType);
for (E e : EnumSet.allOf(enumType)) {
    if (randomPositiveInt() % 2 == 1) {
        set.add(e);
return set;