Java Program to pick random value from enumerations
Program
import java.util.Random;
public class RandomAnswers
{
public enum Answers{
NO, YES, MAYBE, LATER, SOON, NEVER
}
public static void main(String[] args)
{
final Answers[] VALUES = Answers.values();
final int SIZE = VALUES.length;
final Random RANDOM = new Random();
System.out.println(VALUES[RANDOM.nextInt(SIZE)]);
}
}
Output
$ java RandomAnswers
YES
$ java RandomAnswers
NO
$ java RandomAnswers
NEVER
$ java RandomAnswers
LATER