Ad
Code
Diff
  • import random
    
    
    def pi_estimate(n, seed=0):
    
        random.seed(seed)
    
        n_inside = 0
        for i in range(n):
            if random.random()**2 + random.random()**2 < 1:
                n_inside += 1
        return 4 * (n_inside / n)
    • import random
    • def PiEstimate(runs):
    • random.seed(0)
    • inner = 0
    • def pi_estimate(n, seed=0):
    • random.seed(seed)
    • n_inside = 0
    • for i in range(n):
    • if random.random()**2 + random.random()**2 < 1:
    • inner += 1
    • return 4 * (inner / n)
    • n_inside += 1
    • return 4 * (n_inside / n)