Created
September 23, 2018 22:21
-
-
Save DominiquePaul/15b2d466927ff803539d20c47b355586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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