I was playing around with a method to approximate the PI number and realized that the code runs very slowly in the Python 3.6 interpreter, and the process is only using 30% of the processor.
Would you have a way to run this script at full throttle?
from math import sqrt
from random import random
piavg = 0
samples = 10000
scale = 1000
progress = 0
debug_rate = 5
debug_clock = 0
def pis (scale):
pi = 0
points = []
for i in range(scale):
points.append([random(),random()])
for p in points:
if sqrt(p[0] ** 2 + p[1] ** 2) <= 1:
pi += 1
pi /= scale
pi *= 4
return pi
for i in range(samples):
cpi = pis(scale)
progress += 1/samples*100
if debug_rate > 0 and debug_clock == 0:
print(str(int(progress)) + "% encontrado: " + str(cpi))
debug_clock = debug_rate
piavg += cpi
debug_clock -= 1
piavg /= samples
print (piavg)