like math.random(0,100)
print output : 51 times to get number 20
like math.random(0,100)
print output : 51 times to get number 20
uhh
for i = 1, 500 do -- taking anything above 500 attempts is unlikely, or more likely, math.randomseed has been set
local randomNumber = math.random(1,100)
if randomNumber ~= 20 then continue end
print("it took",i,"attempts to roll the number 20")
end
…?
can you do like more than 500? like forever
yes you can just make the
for i = 1, 500 do
make the 500 bigger
yea like what @SubLimitless said but i wouldnt recommend it incase math.randomseed
is set bc your game would just crash
I really do not understand your question but i made something that might be useful
local function GetNumber(target)
local attempts = 0
repeat
attempts = attempts + 1
local RandomNumber = math.random(0, 100)
wait(1)
until RandomNumber == target
return attempts
end
Example of use:
local Attempts = GetNumber(20) -- This will repeat forever until get the number
print("It took " .. Attempts .. " attempts to get the number 20") -- Stop the function when got the number
This is working better thanks!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.