Skip to content

Instantly share code, notes, and snippets.

@antoni
Last active December 27, 2024 13:49
Show Gist options
  • Select an option

  • Save antoni/ae0121449d1da23c2bc0 to your computer and use it in GitHub Desktop.

Select an option

Save antoni/ae0121449d1da23c2bc0 to your computer and use it in GitHub Desktop.
Random enum value in Java
public enum AcademicDegree {
DEGREE_MSC, DEGREE_PHD, DEGREE_PHD_HAB, DEGREE_PROF;
private static final AcademicDegree[] VALUES = values();
private static final int SIZE = VALUES.length;
private static final Random RANDOM = new Random();
public static AcademicDegree getRandomLetter() {
return VALUES[RANDOM.nextInt(SIZE)];
}
}
@Socu22

Socu22 commented Dec 27, 2024

Copy link
Copy Markdown

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment