Skip to content

Instantly share code, notes, and snippets.

@alex-ber
Created August 14, 2021 14:32
Show Gist options
  • Select an option

  • Save alex-ber/0e38d4b4d7b9662d7f89e3b0c2f2138a to your computer and use it in GitHub Desktop.

Select an option

Save alex-ber/0e38d4b4d7b9662d7f89e3b0c2f2138a to your computer and use it in GitHub Desktop.
from numba import jit
import random
@jit(nopython=True)
def monte_carlo_pi(nsamples):
acc = 0
for i in range(nsamples):
x = random.random()
y = random.random()
if (x ** 2 + y ** 2) < 1.0:
acc += 1
return 4.0 * acc / nsamples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment