|
|
Warp wrote:
> Wait a minute... Exactly how do you create a random number generator in
> Haskell?
>
> Not being able to create a RNG function would be rather restrictive in
> many applications...
You write a function that takes a PRNG state and returns a random number
and a new PRNG state.
(That is, if you want *psuedo*-random numbers. If you're after truly
random numbers, you'll obviously need to perform some kind of I/O to get
them, since true randomness comes only from physical sources.)
This is a common idiom in Haskell; write a function that takes an
initial state and returns an answer and a new, modified state. In fact,
there's even a standard monad for automating this so you don't have to
manually pass the state around by hand all the time.
Post a reply to this message
|
|