Skip to content

Instantly share code, notes, and snippets.

@jxnl
Last active August 29, 2015 14:10
Show Gist options
  • Save jxnl/7730df81f682d1ba45ae to your computer and use it in GitHub Desktop.
Save jxnl/7730df81f682d1ba45ae to your computer and use it in GitHub Desktop.
lol pi.py
import random
import math
count_total = 10000
count_inside = 0
for _ in xrange(count_total):
inside_the_unit_circle = (math.hypot(random.random(), random.random()) < 1)
count_inside += 1 if (inside_the_unit_circle) else 0
print 4.0 * count_inside / count
import random
import math
count = 10000
total = sum(map(math.hypot(random.random(), random.random()) < 1 for _ in xrange(count))
print 4.0 * total / count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment