Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to randomly select numbers?

how to select a random number in a range of numbers ie selecting 3 and 7 from a list of 1 to 10 instead of selecting 1,2,3 or 1,2,3,4,5,6,7?

4 answers

Selecting a number, you can use math.random(min, max).

If you want to select a number that's 3 to 7, then do math.random(3,7) in your command bar, and you can see the output will show a number that's randomly generated in 3 to 7.

If you want to make something like randomly generate specific numbers like randomly selecting like 1,4,6,8,9, then you need to use a table and randomly pick a value inside the table by doing like this:

local table1 = {1,4,6,8,9}
local randomNumber = table1[math.random(#table1)]

print(randomNumber)

Check out your output!

If this was correct, mark this as the correct answer, thanks c:

You need to use a table

local table1 = {1,2,3,4,5,6,7,8,9,10}
local randomNumber = table1[math.random(#table1)]

print(randomNumber)

Don't make it harder than it is.

local MyNumber = math.random(1,10)
print (MyNumber)

Done.

This discussion is preserved as it was. New answers, comments, and votes are closed.