Skip to content

Instantly share code, notes, and snippets.

@DKurilo
Created September 20, 2019 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DKurilo/776b72d4e039629c710a192cd4cfca7c to your computer and use it in GitHub Desktop.
Save DKurilo/776b72d4e039629c710a192cd4cfca7c to your computer and use it in GitHub Desktop.
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