Skip to content

Instantly share code, notes, and snippets.

@Kaundur
Last active June 9, 2017 06:57
Show Gist options
  • Save Kaundur/93926be2cb9ab755bed2a4ac9522eb6a to your computer and use it in GitHub Desktop.
Save Kaundur/93926be2cb9ab755bed2a4ac9522eb6a to your computer and use it in GitHub Desktop.
Monte Carlo estimation of pi
import math
import random
count = 0
n = 100000
for i in range(n):
x_pos = random.uniform(0, 1)
y_pos = random.uniform(0, 1)
if x_pos**2 + y_pos**2 <= 1.0:
count += 1
print 4*float(count)/float(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment