Skip to content

Instantly share code, notes, and snippets.

@LinqLover
Last active April 12, 2021 21:35
Show Gist options
  • Save LinqLover/bdb09f460522f8b5ef69d3a3b0f97c33 to your computer and use it in GitHub Desktop.
Save LinqLover/bdb09f460522f8b5ef69d3a3b0f97c33 to your computer and use it in GitHub Desktop.
import numpy as np
import random
from tqdm import tqdm
def test_pi(x, y):
return int(x ** 2 + y ** 2 <= 1) * 4
def test_it(n):
return np.mean([
test_pi(random.uniform(0, 1), random.uniform(0, 1))
for _ in tqdm(range(n))
])
if __name__ == '__main__':
print(test_it(10000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment