Created
November 1, 2024 13:44
-
-
Save vndee/7c309f0eb89eed8b79ec97faa9f7e9ed 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
def estimate_pi(rng, n=1000000): | |
inside = 0 | |
for _ in range(n): | |
x = uniform(rng, -1, 1) | |
y = uniform(rng, -1, 1) | |
if x*x + y*y <= 1: | |
inside += 1 | |
return 4 * inside / n | |
mt = MersenneTwister(42) | |
print(f"π ≈ {estimate_pi(mt)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment