Java Random Enum randomEnum(Class c)

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

Description

random Enum

License

Open Source License

Declaration

private 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 <T extends Enum<?>> T randomEnum(Class<T> c) {
        Random random = new Random();
        int r = random.nextInt(c.getEnumConstants().length);
        return c.getEnumConstants()[r];
    }/*w  ww .  jav  a  2s .co m*/
}

Related

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