Hi.

I'm pleased to announce the availability of my random-stream package.
The cabalized package is available at:
http://haskell.mperillo.ath.cx/random-stream-0.0.1.tar.gz

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 enough.

From package description:
    Portable interface for the operating system source of pseudo
    random data.

    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
    CPython.


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
unsafePerformIO/unsafeInterleaveIO.

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.



Some notes:
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
   http://en.wikipedia.org/wiki//dev/random
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
   numbers.

   For SSL (and Windows) support, the chunk size can be easily changed;
   but for Unix support this seems to not be possible, unless I
   reimplement hGetContents.

   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
   from Data.ByteString.Lazy.Internal?
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.


Usage example:

module Main where

import System.Random
import System.Random.Stream


gen = mkStream
l :: [Int]
l = randoms gen :: [Int]

main = do
  print l




Manlio Perillo
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to