Skip to content

Instantly share code, notes, and snippets.

@evanrinehart
Last active July 22, 2019 22:30
Show Gist options
  • Save evanrinehart/576aa1f90199273b618e0c167d567e12 to your computer and use it in GitHub Desktop.
Save evanrinehart/576aa1f90199273b618e0c167d567e12 to your computer and use it in GitHub Desktop.
pick :: [a] -> IO a
pick urn = do
let n = length urn
when (n < 1) (throwIO (userError "nothing in the urn"))
i <- randomRIO (0,n-1)
return (urn !! i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment