Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How i choose a random number??

Asked by
Gigaset39 111
1 year ago
Edited 1 year ago

Hello, i want to randomly choose a number, so i use:

                   local nr = math.random(1,6)
                   if nr ==1 then
                   end

but this time i want to randomly choose a number like 1,2,3,4 and 6(not 5) butt

                 local nr = math.random(1,6) ---chooses 5 too some times,soo..

how can i make it to choose just 1,2,3,4 or 6?(not 5)

1 answer

Log in to vote
0
Answered by 1 year ago
local function randomNumber()
nr = math.random(1, 6)
if nr == 5 then
randomNumber()
else
break
end

or

Nums = {"1", "2", "3", "4", "6"} -- Allowed Numbers
size = 0
for _ in pairs(Nums) do size = size + 1 end
nr = Nums[math.random(1, size)]
0
now i just realized this question was verry dumb., but thanks for ur answer. Gigaset39 111 — 1y
0
anyway, i didnt understood nothing, maybe iff you used: --- Thisis the list... Gigaset39 111 — 1y
0
im too noob man, Gigaset39 111 — 1y
Ad

Answer this question