Random numbers

Ron Wichers Schreur ronny@cs.kun.nl
Wed, 13 Dec 1995 15:05:24 +0100


Torsten Will <itwill@TechFak.Uni-Bielefeld.DE> wrote:

> The problem is here, where to get the initial state ?
> I'd need a little help from Clean.
 
> // Something like
> getIniState::*WORLD -> (Int,*WORLD)
> // would be sufficient.

This would indeed be an useful function. We may consider adding 
it to a future release, perhaps together with a predefined
pseudo random generator.

A few of the IO examples in the Clean distribution also use
a simple random number generator. In Clean IO programs the
burden of passing the seed is minimal. You can place the
seed in the program state, which is already carried around
for you.

The IO examples get their initial seed by looking at the
clock (using GetCurrentTime). This is sufficient for these
simple games, but not for many other applications.


Jan Krynicky <JKRY3025@barbora.mff.cuni.cz> replied:

> As someone wrote in comp.lang.functional, this explicit state
> passing style is sometimes making it too linear.

The article mentioned (and co-authored) by Rex Page presents a
technique to split the sequence of random numbers.

> The best for applications I don't need the 'pseudo-random'
> features would be something like a standard function (variable).
> [...]
> where the rand would be weird in that, that it would be evaluated
> to different real/int/... numbers.

Such a function did exist in earlier versions of Clean. We decided
to drop it, because we want to maintain referential transparency.


Cheers,

Ronny Wichers Schreur
ronny@cs.kun.nl