Skip to content

Instantly share code, notes, and snippets.

@juanAFernandez
Last active September 13, 2022 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanAFernandez/846d49905dc0f09f92b9fa5529cb217b to your computer and use it in GitHub Desktop.
Save juanAFernandez/846d49905dc0f09f92b9fa5529cb217b to your computer and use it in GitHub Desktop.
How to get random keys from any enum
function randomFromEnum(TEnum: any): typeof TEnum {
return Object.values(TEnum)[Math.floor(Math.random() * (Object.keys(TEnum).length - 1 + 1))];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment