Monte Carlo estimation of PI


Author Message
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 427
Posted: 02:10pm 08 Sep 2020      

  Volhout said  Confirm

MMbasic DOS version get's accurate up to 3 decimal places, not more.
The DOS version uses 64 bit variables, so should be capable of higher accuracy than 3 decimal places.

Maybe it is the randomizer. If your resolution on the random numbers is not high enough you keep testing the same 'pixels' in your circle.

Interesting...


Just compared this exact algorithm in (cough) Python (using random and math libraries) and MMBasic.

After 10,000,000 iterations:

Python:  3.1416352
MMBasic: 3.1409356

As far as I can see, nothing wrong there.   So both look like at best 2-3dps with 10,000,000 iterations.  The PC took seconds (4GHz, 4-core) - whereas the CMM2 took minutes -- but this wasn't a speed exercise.

I'm happy with that -- not going to test further.

Might find a better algorithm for PI though.

Cheers
Nim