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

math.random only by 10s?

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

✓ Accepted answer

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)

1 comment

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.

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?

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