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

math.random only by 10s?

Asked by
Bman8765 270 Moderation Voter
9 years ago

The title is a little difficult to understand but basically I want to know is it possible, and if so how, do you generate random numbers only by 10's

local randomnum1 = math.random(50, 500)

I then want the answer to be one of the following: 60, 70, 80, 90, 100, etc. (I think you get the point). If anyone knows how to some help would be awesome, I tried looking through the roblox and LUA wiki but couldn't really find anything.

2 answers

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

I would recommend getting a small number, then multiplying it by 10.

For example, if we wanted a random number between 1 and 50, but only counting by 10's - 10, 20, 30, 40, 50 - we could get a random number between 1 and 5, then multiply that by 10. This works because 1 * 10 is 10, 2 * 10 is 20, 3 * 10 is 30, etc.

local randomNum = math.random(1,5)
print(randomNum * 10)
0
Lol I figured that out right before you if I look about but thanks, I started to get the idea while I continued working. Bman8765 270 — 9y
Ad
Log in to vote
0
Answered by
Bman8765 270 Moderation Voter
9 years ago

I think I found the solution (yes this is me answering my own question) couldn't I just do this

local randommath = math.random(1, 50)

local finalmath = randommath* 10

Just curious if that was right guys?

Answer this question