Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2012 04:24
Show Gist options
  • Save anonymous/1890187 to your computer and use it in GitHub Desktop.
Save anonymous/1890187 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#George Vamos
# Most simple minded implementation of monte carlo pi
import math, random
MAX=1000000
hits = 0
rounds = 0
for i in range(MAX):
rounds += 1
x=random.random()
y=random.random()
d = math.sqrt((x*x)+(y*y))
if (d < 1.0): hits += 1
print("%d,%d,%f" % (rounds,hits,((4.0 * hits)/rounds)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment