Here you can find the source of randomEnum(Class
public static <T extends Enum<?>> T randomEnum(Class<T> cls, T exceptValue)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { public static <T extends Enum<?>> T randomEnum(Class<T> cls, T exceptValue) { int x = new Random().nextInt(cls.getEnumConstants().length); T t = cls.getEnumConstants()[x]; return t.equals(exceptValue) ? randomEnum(cls, exceptValue) : t; }// ww w . j ava 2 s . c o m public static <T extends Enum<?>> T randomEnum(Class<T> cls) { return randomEnum(cls, null); } }