Random numbers
Jan Krynicky
JKRY3025@barbora.mff.cuni.cz
Tue, 12 Dec 1995 21:58:46 +0200
> Subject: Re: Random numbers
> From: Torsten Will <itwill@TechFak.Uni-Bielefeld.DE>
>
> Hello,
>
> > How I get a random number in Clean?
>
> In a purely functional language it is impossible to get real random
> numbers. But there are two possibilies to solve this problem:
>
> 1. Use a unique type for a random-generating function, but I don`t
> know how to do this.
>
> 2. For some problems it is enough to generate pseudo-random numbers
> (numbers that SEEMS to be random, but are reproducable).
> In MIRANDA I write a function like that:
>
> ////////////// Very simple program for generating pseudo random numbers
> // Miranda-script
> // pseudoRands gives a list of pseudo-randoms between 1..10
>
> startvalue :: num // num is like 'int' in C
> startvalue = 42
>
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.
>
> Tschau, Torsten.
>
As someone wrote in comp.lang.functional, this explicit state passing
style is sometimes making it too linear.
The best for applications I don't need the 'pseudo-random' features
would be something like a standard function (variable).
: rand::Rand // not unique!
and
: instance toReal Rand
: instance toInt Rand
...
where the rand would be weird in that, that it would be evaluated to
different real/int/... numbers.
But it can (I think) be done only by the developers of the compiler.
\v Cau, Jenda