Aleksey Khudyakov :
I think design of Random type class basically precludes efficient generators with large periods and consequently large state.
Look at next function:

> next :: g -> (Int, g)

It means that state has to be copied but for efficiency we want to
mutate it in place. I consider Random type class a failure and ignore
it.

P.S. For monte-carlo and thing like that I'd recommend mwc-random
it more featureful than mersenne-random and don't rely on global state
I am afraid that Aleksey Khudakov confuses a few things.

1. Mersenne Twister, AND congruential generators AND the Marsaglia stuff, all use some kind of "seed", all are stateful. There are no miracles. Just look the agressive monadization, the form of defaultSeed, etc. within MWC.hs, before saying that this generator doesn't rely on some global state.

2. In the standard generator stuff the state is stored in IoRefs and is not "copied". Did Aleksey ever look inside the sources of these generators? In any case, the seed changes after each generation, and must be stored somewhere.

3. The API question is a conventional one. People who are really unhappy, may make their own interfaces, or give such a mini-project as a students' assignment, instead of weeping that the library is lousy and should be ignored. E. g., I wanted random numers in some purely functional, lazy context, and I didn't want the existing interface ; I manufactured a lazy stream interface, and that was all. "Look Ma!: no global state..."

4. L'Ecuyer signalled some 15 years ago that MWC generators introduce some bias on the most significant bits (complementary MWC are safer). This is less annoying that the last bits periodicity of simple congruential generators, but for SOME Monte-Carlo it may be harmful.

=======

In general, I believe that saying publicly that some part of the available library is a failure, should be avoided, unless accompanied by some SERIOUS analysis, and - if possible - some constructive suggestions.

With my thanks to all people who made those generators however imperfect they are. Only Mister Nobody is perfect.

Jerzy Karczmarczuk


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

Reply via email to