Skip to content

Instantly share code, notes, and snippets.

View pprzetacznik's full-sized avatar

Piotr Przetacznik pprzetacznik

View GitHub Profile
from random import random
NUM_SAMPLES = 10000
def sample(p):
x, y = random(), random()
return 1 if x*x + y*y < 1 else 0
count = sc.parallelize(xrange(0, NUM_SAMPLES)).map(sample) \
.reduce(lambda a, b: a + b)
print "Pi is roughly %f" % (4.0 * count / NUM_SAMPLES)