Log in to vote
0

# How to use Math.random? I forgot it

Asked by 2 years ago

Hey there! I totally forgot how math.random worked.

Could anyone explain this to me?

I need it for a FOV changer that just changed the fov at random moments.

### 2 answers

Log in to vote
2
Answered by
Xapelize 2326
2 years ago

A math.random(min,max) is a CODE for getting a random number.

print(math.random(1,10))


Output :

8

This CODE means to print a number that 1 to 10. Let's do another code :

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


Output :

math.random(1,10)

OH, WHAT'S WRONG? Aha, ignore the " " in the print!

Output :

7

etc :

local number1 = math.random(1,10)

print("OMG, THE NUMBER IS ".. number1)


Output :

OMG, THE NUMBER IS 4

Ok, thanks for watching, have a nice day and happy coding :) If you have any question comment below :D

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

math.random() gets a random number when specified. It's inclusive. example:

 local r=math.random(1,4)
print(r)