Created
June 4, 2011 15:51
-
-
Save jb55/1008001 to your computer and use it in GitHub Desktop.
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
| import Control.Monad | |
| import Test.QuickCheck | |
| import Test.QuickCheck.Gen | |
| import System.Random | |
| import System | |
| data Serial = Serial String Int | |
| instance Show Serial where | |
| show (Serial prefix number) = prefix ++ show number | |
| instance Arbitrary Serial where | |
| arbitrary = do | |
| prefix <- vectorOf 3 $ elements ['A'..'Z'] | |
| number <- choose (10000, 99999) | |
| return $ Serial prefix number | |
| serialGen :: Int -> [Serial] | |
| serialGen seed = unGen arbitrary (mkStdGen seed) 9999999 | |
| main = do | |
| args <- getArgs | |
| case map read args of | |
| [] -> putStrLn "serial <number of serials> [seed]" | |
| [n] -> go n 2 | |
| [n, seed] -> go n seed | |
| where | |
| go n seed = mapM_ print (take n $ serialGen seed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment