[Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)
jonathanccast at fastmail.fm
Tue Nov 6 22:15:47 EST 2007
On 6 Nov 2007, at 3:56 PM, Yitzchak Gale wrote:
> I wrote:
>>> There is still a problem here - my code (and also
>>> all of the previous posters, I think) clobbers the random
>>> generator, rendering it unusable for future calculations.
>>> In this case that is probably not a problem, but it
>>> is a bad habit to get into, and not very polite.
> Jonathan Cast wrote:
>> Nope. newStdGen is specified in terms of split, which means it
>> leaves the random generator in a state independent of the generator
>> it returns. Perfectly safe. (I think you think you used getStdGen).
> I was referring to randoms and randomRs.
> They clobber the generator. You can then get
> a new one using newStdGen, but that forces
> you back into the IO monad.
Oh, of course. Or call split first.
More information about the Haskell-Cafe