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

How would I math.random more than 1 variable?

Asked by 9 years ago

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

math.random(1, 2)
0
Could you please re-word your question? It doesn't make any sense. Goulstem 8144 — 9y

3 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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)
Ad
Log in to vote
0
Answered by
KoreanBBQ 301 Moderation Voter
9 years ago

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)]
Log in to vote
-2
Answered by 9 years ago

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

Answer this question