1 import "StandardLibrary"
\r
5 """This function returns either 0 or 1 such that
\r
6 the expected value is pi/4"""
\r
7 approximatePi :: () -> <Random> Double
\r
8 approximatePi () = if x*x + y*y < 1 then 1 else 0
\r
13 averageOfNRepeats n f = sum [f () | n <- [1..n]] / fromInteger n
\r
15 betterApproximatePi () = averageOfNRepeats 1000 approximatePi * 4
\r
17 main = withSeed 13 (betterApproximatePi ())
\r