[Haskell-cafe] [ANN] random-stream package
manlio_perillo at libero.it
Thu Mar 19 06:55:16 EDT 2009
I'm pleased to announce the availability of my random-stream package.
The cabalized package is available at:
Note that I have not uploaded it on Hackage, and I do not plan to upload
it in the near future, at least until I will repute the package mature
From package description:
Portable interface for the operating system source of pseudo
Supported sources are Unix /dev/urandom, Win32 CryptGenRandom and
OpenSSL pseudo random numbers generator.
This package is based on idea from os.urandom implementation, in
The idea is to view the system pseudo random generator as a stream of
infinite random bytes.
So, I have used a lazy bytestring, and
The underlying data is:
newtype Stream = Stream L.ByteString
and the constructor *is exposed*.
The package configuration *must* be done using a flag to specify the
"source" to use.
As an example:
runghc Setup.hs configure -O2 -fHAVE_URANDOM
runghc Setup.hs configure -O2 -fHAVE_SSL
runghc Setup.hs configure -O2 -fHAVE_WIN32_CRYPT
If the flag is not specified, the compilation will fail.
Note that Windows it not yet supported.
The stream generator implements tha RandomGen interface.
1) The system *pseudo* random generator is used.
As an example, on Linux, /dev/random produces "true" random numbers,
but it may block if there is not enough entropy in the system.
More details on
2) When reading data, the lazy bytestring chunk size is used.
The default chunk size, however, is fine when reading from a regular
file, but may not be the best choice when reading pseudo random
For SSL (and Windows) support, the chunk size can be easily changed;
but for Unix support this seems to not be possible, unless I
The Data.ByteString.Lazy module have an hGetContentsN function.
Unfortunately it is not exposed.
I find this annoying; is it possible to export the *N functions
3) I have tested the package on Debian Linux Etch, using GHC 6.8.2.
Feedback will be appreciate.
I not sure about some details.
module Main where
gen = mkStream
l :: [Int]
l = randoms gen :: [Int]
main = do
More information about the Haskell-Cafe