[Haskell-cafe] Re: True Random Numbers

Ertugrul Soeylemez es at ertes.de
Sat Apr 3 09:20:10 EDT 2010

Hello Christopher,

unfortunately this is not a "better StdGen", because it still uses the
poor PRNG algorithm of StdGen.  You can get better statistic properties
by using a package like mwc-random or mersenne-random.

However, if you want (an approximation of) truely random numbers, you
need to read from /dev/random.  If you prefer pseudo-random numbers, but
need cryptographic strength, you can use the "OpenSSL.Random" module
from the HsOpenSSL package.


Christopher Done <chrisdone at googlemail.com> wrote:

> I've used this one before:
> betterStdGen :: IO StdGen
> betterStdGen = alloca $ \p -> do
>    h <- openBinaryFile "/dev/random" ReadMode
>    hGetBuf h p $ sizeOf (undefined :: Int)
>    hClose h
>    mkStdGen <$> peek p

nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list