[Haskell-beginners] uses of random number generators

Michael P Mossey mpm at alumni.caltech.edu
Fri Jul 24 01:35:04 EDT 2009


Hello,

I have an application for random numbers. So far, in my journey with Haskell, I 
have learned basics and a few things about monads, and I was hoping I could get 
some guidance how to employ random # gens.

I need to run some simulated experiments to calculate some statistics by a Monte 
Carlo method.

There are several components to the experiment, but one component is:

- Given a hat with 5 red squares and 5 blue squares, draw one square at a time, 
note its color, for a total of 8 squares. Remember the order of the 8 squares.

Another function will take two inputs each of which is "red" or "blue". If they 
are the same color, return the other color. Otherwise "toss a coin" to determine 
which color to return.


-- this uses Bool rather than "red" "blue" for obvious reasons.
balanceColors :: Bool -> Bool -> Bool
balanceColors c1 c2 =
     if c1 == c2
       then not c1
       else -- flip coin --

Can I get a few examples or pointers? I believe I will have to run this in a 
State monad or the IO monad, will I not?

Thanks,
Mike


More information about the Beginners mailing list