Skip to content

Instantly share code, notes, and snippets.

@sol
Forked from mklinik/gist:1803869
Created February 12, 2012 07:17
Show Gist options
  • Save sol/1807031 to your computer and use it in GitHub Desktop.
Save sol/1807031 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Random
randomEnum :: forall a. (Enum a, Bounded a) => IO a
randomEnum = do
let minBoundInt = fromEnum (minBound :: a)
let maxBoundInt = fromEnum (maxBound :: a)
randomInt <- Random.randomRIO (minBoundInt, maxBoundInt)
return $ toEnum randomInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment