Mock.hs 569 Bytes
Newer Older
Nicolas Lenz's avatar
Nicolas Lenz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Mock (mockAlternate, mockRandom) where

import Data.Char
import Data.List
import System.Random
import Data.Time.Clock.POSIX

toUpperBy :: String -> [Bool] -> String
toUpperBy (c:cs) (True:bs) = toUpper c : toUpperBy cs bs
toUpperBy (c:cs) (False:bs) = c : toUpperBy cs bs
toUpperBy (cs) [] = cs
toUpperBy [] _ = []

mockAlternate :: String -> String
mockAlternate str = toUpperBy str $ intersperse True $ repeat False

mockRandom :: String -> IO String
mockRandom str = do
    time <- fmap round getPOSIXTime
    return $ toUpperBy str $ randoms $ mkStdGen time