import Random import System.Directory import System.Environment import System.Exit import Monad swap l a b | b > a = map (swap' b a l) $ zip l [0..] | a == b = l | a > b = map (swap' a b l) $ zip l [0..] where swap' a b l (v,k) | k == a = l !! b | k == b = l !! a | otherwise = v shuffle l = foldM shuffle' l $ reverse $ [1..length l - 1] where shuffle' l n = randomRIO(0, n-1) >>= return . swap l n main = do a <- getArgs main' a where main' a | length a /= 2 = getProgName >>= \x -> putStrLn ("Usage: " ++ x ++ " ") >> exitWith (ExitFailure 1) | otherwise = do d <- getDirectoryContents dir l <- filterM (doesFileExist . (++) (dir ++ "/")) d >>= shuffle mapM putStrLn $ take num l where dir = a !! 0 num = read $ a !! 1