RosettaCodeData/Task/Monte-Carlo-methods/BASIC256/monte-carlo-methods-2.basic
2023-07-01 13:44:08 -04:00

17 lines
411 B
Text

print " Number of throws Ratio (Pi) Error"
for pow = 2 to 8
n = 10 ^ pow
pi_ = getPi(n)
error_ = 3.141592653589793238462643383280 - pi_
print rjust(string(int(n)), 17); " "; ljust(string(pi_), 13); " "; ljust(string(error_), 13)
next
end
function getPi(n)
incircle = 0.0
for throws = 0 to n
incircle = incircle + (rand()^2 + rand()^2 < 1)
next
return 4.0 * incircle / throws
end function