#! /usr/bin/env python3 # import numpy as np def simulate_many ( n ): # simulate_many estimates the average distance. # # Input: # # integer n, the number of simulations. # # Output: # # real average, the average distance between two flies in the # unit square, after n simulations. # average = 0.0 for test in range ( 0, n ): p1 = np.random.rand(2) p2 = np.random.rand(2) d = np.linalg.norm ( p1 - p2 ) average = average + d average = average / n return average