Skip to content

Instantly share code, notes, and snippets.

@atton
Created December 26, 2014 11:59
Show Gist options
  • Save atton/4f60caeac356d0b78254 to your computer and use it in GitHub Desktop.
Save atton/4f60caeac356d0b78254 to your computer and use it in GitHub Desktop.
password.hs
import System.Random
import System.Environment
import Data.Maybe
main = do
arg <- getArgs
gen <- newStdGen
putStrLn $ fromMaybe "" $ listToMaybe arg >>= (return . (password gen) . read)
-- putStrLn . (password gen) $ fromMaybe 0 $ listToMaybe arg >>= return . read
-- putStrLn . (password gen) . read $ fromMaybe "0" $ listToMaybe arg
where
characters = ['0'..'9']++['a'..'z']++['A'..'Z']++['!','$','%','@','#']
password g x = take x $ zipWith (!!) (repeat characters) $ randomRs (0, (length characters) - 1) g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment