Java Random Enum RandomEnum(Class c)

Here you can find the source of RandomEnum(Class c)

Description

Random Enum

License

Open Source License

Declaration

public static <T extends Enum<?>> T RandomEnum(Class<T> c) 

Method Source Code


//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];
    }
}

Related

  1. randomEnum(Class c)
  2. randomEnum(Class clazz)
  3. randomEnum(Class cls, T exceptValue)
  4. randomEnumSet(Class enumType)