RosettaCodeData/Task/Monte-Carlo-methods/Liberty-BASIC/monte-carlo-methods.basic

16 lines
242 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
for pow = 2 to 6
n = 10^pow
print n, getPi(n)
next
end
function getPi(n)
incircle = 0
for throws=0 to n
scan
incircle = incircle + (rnd(1)^2+rnd(1)^2 < 1)
next
getPi = 4*incircle/throws
end function