Here you can find the source of RandomEnum(Class
public static <T extends Enum<?>> T RandomEnum(Class<T> c)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static Random rand = new Random(); public static <T extends Enum<?>> T RandomEnum(Class<T> c) { return RandomEnum(c, 0); }/* w w w . j a va2 s . c om*/ public static <T extends Enum<?>> T RandomEnum(Class<T> c, int offset) { int x = offset + rand.nextInt(c.getEnumConstants().length - offset); return c.getEnumConstants()[x]; } }