Scripting Lesson 009: Random Numbers

To make random numbers, you should use the math.random() function. It is a core function: using Lua elsewhere makes it still work. There can be 0, 1, or 2 integers (integers are numbers not with decimals) inside the parentheses. If there are none, then the number it chooses is between 0 and 1 exclusive. To increase the numbers it goes between without adding arguments, multiply or divide. If there is 1 number, then it returns an integer between 1 and that integer. It returns an integer. If there are 2 integers, the function returns a number between these 2. Remember, if there are 1 or 2 numbers, it returns an integer. Remember, NEVER make the numbers too big, so thou shalt never reach 2147483647 (2^31-1) in either argument. As said earlier, if you have 2 integers, it will choose either those numbers or a number in between. However in this example, since there are no integers in between 0 and 1, it will choose either one of them in a 50-50 chance.

In this next example, there is no argument and no number in the () so therefore the number is a decimal between 0 and 1, however, the script also features *2-1 (* means multiply and - means divide) so there will be changes to the number (which is why it will be in between -1 and 1)

Now I will show you how to use this in greater depth. Here is a script that uses the number value to change the surrounding area.

This is one of the ways you can use this function in everyday use. Good luck with working with this

-Domswolf and Age King Snapcash