Skip to content

Instantly share code, notes, and snippets.

@jb55
Created June 4, 2011 15:51
Show Gist options
  • Select an option

  • Save jb55/1008001 to your computer and use it in GitHub Desktop.

Select an option

Save jb55/1008001 to your computer and use it in GitHub Desktop.
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