#!/usr/bin/runghc -- These methods do CSPRNG -- https://stackoverflow.com/questions/20889729/how-to-properly-generate-a-random-bytestring-in-haskell -- https://tommd.github.io/posts/RNG-Bench.html -- ghc-crypto-api (old), ghc-cryptonite (retired), ghc-crypton (current) have similar API -- sudo dnf install ghc-crypton-* ghc-entropy* import Crypto.Random (getRandomBytes) import Data.ByteString (ByteString) import System.Entropy generateSecureRandomBytes :: Int -> IO ByteString generateSecureRandomBytes n = getRandomBytes n main :: IO () main = do -- With Crypton/Cryptonite/Crypto-api randomBytes <- generateSecureRandomBytes 16 print randomBytes -- With System.Entropy randBytes <- getEntropy 16 print randBytes