Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created September 1, 2012 13:15
Show Gist options
  • Save dtchepak/3572960 to your computer and use it in GitHub Desktop.
Save dtchepak/3572960 to your computer and use it in GitHub Desktop.
random strings (w/out quickcheck)
randomChar :: (RandomGen g) => State g Char
randomChar = state $ randomR ('a','z')
randomStringWithLength :: (RandomGen g) => Int -> State g String
randomStringWithLength i = replicateM i randomChar
randomString :: (RandomGen g) => State g String
randomString = state $ \g ->
let (charsToGen, g') = randomR (1,10) g
in runState (randomStringWithLength charsToGen) g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment