Skip to content

Instantly share code, notes, and snippets.

@smartinov
Created November 28, 2016 08:39
Show Gist options
  • Save smartinov/bfaf3c90458b371d4c1b215528f829d0 to your computer and use it in GitHub Desktop.
Save smartinov/bfaf3c90458b371d4c1b215528f829d0 to your computer and use it in GitHub Desktop.
java random enum
import java.util.Random;
public class RandomEnum {
public static <T extends Enum<?>> T from(Class<T> clazz) {
int x = new Random().nextInt(clazz.getEnumConstants().length);
return clazz.getEnumConstants()[x];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment