import numpy as np
import math
import matplotlib.pyplot as plt
%matplotlib inline
goodpts = []
badpts = []
trials = 5000
good = 0
for i in range(trials):
x = np.random.random()
y = np.random.random()
if math.sqrt(x ** 2 + y ** 2) <= 1:
good += 1
goodpts.append((x, y))
else:
badpts.append((x, y))
4 * good / trials
3.1216
g = np.array(goodpts)
b = np.array(badpts)
fig = plt.figure()
ax = fig.add_subplot(111, aspect="equal")
plt.plot(g[:,0], g[:,1], "o")
plt.plot(b[:,0], b[:,1], "o")
[<matplotlib.lines.Line2D at 0x1121a4278>]
g[:,1]
array([ 0.30058286, 0.60734095, 0.46297716, ..., 0.30195455, 0.21865179, 0.35318917])