Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created September 25, 2012 04:45
Show Gist options
  • Save dtchepak/3780022 to your computer and use it in GitHub Desktop.
Save dtchepak/3780022 to your computer and use it in GitHub Desktop.
Random date string
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