[Haskell-cafe] approximating pi

Benjamin L. Russell dekudekuplex at yahoo.com
Mon Apr 28 00:24:12 EDT 2008


Assuming the square had 100 pixels per side, on the average, approximately how many random pixels should be plotted in the square before obtaining a reasonably good estimate of pi?

Benjamin L. Russell

--- On Mon, 4/28/08, jerzy.karczmarczuk at info.unicaen.fr <jerzy.karczmarczuk at info.unicaen.fr> wrote:

> From: jerzy.karczmarczuk at info.unicaen.fr <jerzy.karczmarczuk at info.unicaen.fr>
> Subject: Re: [Haskell-cafe] approximating pi
> To: haskell-cafe at haskell.org
> Date: Monday, April 28, 2008, 9:54 AM
> Don Stewart writes: 
> 
> > Ry Dahl:
> >> By picking points randomly from a square one can
> calculate pi.
> ...
> >> What is the best way to express this algorithm in
> Haskell?
> > 
> > Using a random generator, such as System.Random or
> > System.Random.Mersenne, generate random numbers in
> your range,
> > testing if they're inside the circle, and loop
> until your limit
> > condition is reached. 
> > 
> > The full program is about 10 lines or so, so
> shouldn't be too hard to
> > work out, once you've worked out how to generate
> Doubles from
> > System.Random.random
> 
> Ry Dahl seems to know Ruby. Ruby has also comprehensions.
> So, why not use
> 'randoms' to generate an infinite list of them,
> 'take' some N, and then
> 'sum' 1 on randoms filtered by the circle
> condition. I think that you
> won't need full 10 lines of code... 
> 
> Jerzy Karczmarczuk 
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list