Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
math.randomseed(os.time())
local trials = 100
local iter = 1
local targetpercent = 0.99
function recur()
local tot = 0
for c = 1, trials do
local b = false
local x = 1
while b == false and x <= iter do
r = math.random(127)
if r <= 127 and r > 63 then
tot = tot + 1
b = true
end
x = x + 1
end
end
if tot/trials <= targetpercent then
iter = iter + 1
x = 1
tot = 0
recur()
end
end
local totiter = 0
for c = 1, 100 do
recur()
totiter = iter + totiter
iter = 1
end
print (totiter/trials)
print ("588 tier 7, 268 tier 6, 120 tier 5, 58 tier 4, 31 tier 3, 15 tier 2, 7 tier 1")
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more