[Haskell] Re: About Random Integer without IO

Keean Schupke k.schupke at imperial.ac.uk
Fri Nov 12 05:57:41 EST 2004

Hmm... It is impossible to write a purely functional program to generate 
random numbers. Not only that it is impossible for a computer to 
generate random numbers (except using hardware like a noise generator). 
Pseudo random numbers require a seed. Functional programs by definition 
only depend on their inputs - therefore the seed is either fixed (same 
numbers each run) or one of the inputs (which means it must be IO).

So all programs have the same limitation, and ising the IO Monad to 
initialise a sequence of
random numbers is the way to do it (In any language this _will_ involve IO).

I can see an argument that command line parameters to a program should 
be presented
as arguments to 'main' and not as the result of an IO action - but this 
would only help
eliminate any IO in the case where the seed was to be input by the user.


karczma wrote:

> Thomas Davie writes, commenting my statement that one does need any
> 'stateful' (monadic, etc.) RN generator initializer within the program,
> since you can always pass a parameter during its launching.
>> While I agree that it is often useful to start your program with 
>> different parameters each time to seed the random number generator, I 
>> would argue that this is often inappropriate - supposing we are 
>> writing a very simple program to roll a virtual dice.  If the user 
>> finds one input that rolls a six, they can then use this repeatedly.  
>> Reading an initialisation file is back to the situation of using IO 
>> to generate our seed.
> I believe there is no conflict between us, I agree with you. But the
> difference betwen us is that I do think rather about serious usages of 
> RN,
> not about contrived examples. I think that if somebody faced a purely
> functional program to roll a virtual dice, there would be a good deal
> of sheer madness involved, either the conceptor/implementor madness, or
> the user's, or both. Haskell is not for *that* kind of problems.
> I used Haskell and Clean to do some Monte-Carlo, or to generate sound
> using random algorithms (say, Karplus-Strong string initialized by a 
> white
> noise). I generated random fractals, etc. It didn't cost me anything to
> put different initializations by hand on every run when I wanted to have
> different behaviour. But it was MUCH more important to repeat the same
> sequence, e.g., after making fast some nice fractal sketch, I relaunched
> the program with bigger size/precision, but exploiting the same random
> sequence. I repeat, such is my philosophy. Yours is easier, since you are
> just discussing, most probably you never used RN for a serious work. If
> I am wrong, I apologize.
> Jerzy K.
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

More information about the Haskell mailing list