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

How would I math.random more than 1 variable?

I mean like, if I have 2 numbers I want to be randomly chosen, would it go like this?

math.random(1, 2)

1 comment

0

Could you please re-word your question? It doesn't make any sense.

3 answers

The math.random function takes in two numbers, the minimum number, and the maximum number to compute a random number with. It returns the random number computed betwixt the two. To set two random numbers you have to use the function two different times.

local num1 = math.random(1,2)
local num2 = math.random(1,2)

Or if you have a list of values and you want to pick one randomely, I'd do

local list={a,b,c,d,e}
local random=list[math.random(1,#list)]

No, you must use a for loop to select z (for _ = 1, z do) numbers from x to y (math.random(x,y)), I will give you an example of printing 2 random numbers choosen from 1 to a million.

for _ = 1,2 do
print(math.random(1, 1000000)
end

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