Created
September 25, 2012 04:45
-
-
Save dtchepak/3780022 to your computer and use it in GitHub Desktop.
Random date string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
randomMonth :: (RandomGen g) => State g String | |
randomMonth = | |
let monthNames = [ "January", "February", "March" | |
, "April", "May", "June" | |
, "July", "August", "September" | |
, "October", "November", "December" | |
] | |
in (monthNames !!) <$> randomNumber (1,11) | |
randomNumber :: (RandomGen g) => (Int,Int) -> State g Int | |
randomNumber = state . randomR | |
randomDateString :: (RandomGen g) => State g String | |
randomDateString = | |
let day = randomNumber (1,28) | |
year = randomNumber (1940,2020) | |
display d month y = show d ++ " " ++ month ++ " " ++ show y | |
in liftM3 display day randomMonth year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment