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

How to do math.random -numbers?

Asked by 9 years ago

I am trying to get random - numbers in-between 2 numbers.

0
the minus is == negitive xXScriptzXx 0 — 9y

3 answers

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

math.random(lownumber, highnumber) will give you a random integer between the two given numbers. If the numbers are not given, it will generate a random decimal between 0 and 1.

print(math.random(1, 10))
print(math.random())

On a side note, you should have been able to find this on the wiki. Simply searching 'random numbers' would have given you what you need. Please do your research before coming here.

Ad
Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

Sorry if I have misinterpreted however to get a minus you could do

x = math.random(1, 10)
y = x - (x*2)

This will make y a negative number in between -1 and -10

Log in to vote
-1
Answered by 9 years ago
  • == Negitive...
0
It works the same with negatives, just make sure the smaller number is first, i.e. "print(math.random(-10,-1))" Perci1 4988 — 9y

Answer this question