Created
September 20, 2019 02:21
-
-
Save DKurilo/776b72d4e039629c710a192cd4cfca7c 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
module Main where | |
import Data.Char | |
import Data.ByteString.Char8 hiding (all, putStrLn) | |
import System.IO | |
getStr _ 0 _ = return "" | |
getStr h n p = do | |
c <- unpack <$> hGet h 1 | |
if all p c | |
then do | |
s <- getStr h (n - 1) p | |
return $ c ++ s | |
else getStr h n p | |
get32 h = hSetBuffering h NoBuffering >> getStr h 32 (and . ([isAlphaNum, isAscii] <*>) . pure) | |
get32Rand = withFile "/dev/urandom" ReadMode get32 >>= putStrLn | |
main :: IO () | |
main = get32Rand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment