[Haskell-cafe] Re: Why does RandomIO need the unsafePerformIO hack?
karczma at info.unicaen.fr
Fri Dec 3 06:49:44 EST 2004
John Meacham wrote:
>On Fri, Dec 03, 2004 at 10:05:08AM +0000, Graham Klyne wrote:
>>BTW, if the goal is to have a random number generator as a pure (non-IO)
>>function, I *do* think there's a reasonable semantic objection here.
>Oh yes. no one is wanting that.
Sometimes I am surprised how much energy goes into such details
as discussed under this (or other) topic, and for weeks *nobody*
says a single word about the applications. What for? When used?
Personally I never paid too much attention to this monadic Random
stuff, since in my applications I could always use PURE FUNCTIONAL
usage of RN generators.
1. Using (lazy) streams of random numbers. I needed a noise signal,
I produced a noise signal, by iterating a generator.
2. I needed a multidimensional Perlin noise. One localized loop permitted
to fill an array with pseudo-random values, and then a "random"
f(x,y,z) is obtained by indexing and some intricate combinatorics which
decorrelates the values.
3. There exist a category of *ergodic* functions, *PURE* functions which
behave erratically when the argument, integer, n= 0, 1, 2, 3, ... It
like noise, perfectly usable. This has been used by Greg Ward in
graphics, and it should be published somewhere in Graphics Gems.
This function is based on a polynomial with the bits XORed and truncated
to (say) 32 bits. Trivial to do in languages which work with machine
integers, ignoring overflow (like Clean). More difficult in Haskell.
More information about the Haskell-Cafe