Skip to content

Instantly share code, notes, and snippets.

@DominiquePaul
Created September 23, 2018 22:21
Show Gist options
  • Save DominiquePaul/15b2d466927ff803539d20c47b355586 to your computer and use it in GitHub Desktop.
Save DominiquePaul/15b2d466927ff803539d20c47b355586 to your computer and use it in GitHub Desktop.
import random
num_samples = 10000000
def inside(p):
x, y = random.random(), random.random()
return x*x + y*y < 1
count = sc.parallelize(range(0, num_samples)).filter(inside).count()
pi = 4 * count / num_samples
print(pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment