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

Confused with how math random works, can I get help?

Asked by 7 years ago

So, I know math random selects a random number. But can you set it to select a number within a range you assign? Something like

1math random 10 - 20

Sorry about my LUA, I'm still learning! Just need this question answered, because i'm confused.

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
1math.random(10,20)

gets a random number from 10 - 20 as you said.

Remember to use . and ()

if this doesn't work then open the output and type this in:

1print(math.random(10,20))
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Example

01Baseplate = game.Workspace.BasePlate
02 
03while true do
04wait(1)
05ColorstoChooseFrom = math.random(1,3)
06 
07if ColorstoChooseFrom == 1 then
08Baseplate.BrickColor = BrickColor.new("Red")
09end
10 
11if ColorstoChooseFrom == 2 then
12Baseplate.BrickColor = BrickColor.new("Blue")
13end
14 
15if ColorstoChooseFrom == 3 then
16Baseplate.BrickColor = BrickColor.new("Green")
17 end
18end

Thats An Exapmple on How Math.Random Works

Answer this question