@mikrom: yeah you're right, I noticed that!
In my opinion the fact that with n = 4678343 we get a better result than with n = 2147483647 could be possibly due to the fact that also in this plot http://upload.wikimedia.org/wikipedia/commons/7/7d/Errore_montecarlo_calcolo_pi_greco.PNG the error...
@mikrom: you're right! call random_number works better than rand(), even though the convergence is very slow.
I found this picture on Wikipedia that shows the percent error as a function of the number of drops, and it says that overall the program generated 1,37 billion drops, which is similar...
@mikrom: and how could you do that? In fact, in another situation as well I needed a number bigger than 2^31-1, but I didn't manage to solve it. Is there any way?
Whoa thank you very much!
Both of your answers were very helpful!
Thanks for the code, it's really useful to see another way to answer the problem.
And I didn't know I wasn't using double precision numbers for all my values. You've just opened a new world for me!
Thank you.
Hello everyone, I'm trying to calculate pi by following an idea on Wikipedia
http://en.wikipedia.org/wiki/Monte_Carlo_method
In practice I generate some random points (x,y) in a square (side=1) and counting how many points are in the square and how many are in the circle (radius=1) remembering...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.