So, lets say I wanted a script to calculate a random number from 0 - 100. How would I do that?
In other words, I want a script to calculate a random number for each possible number for rotation Y. How would I do that? And if you can, send me a wiki link so I can learn more.
There's a function precisely for that in Lua's math library appropriately named random
. You can use this to return a random number within a range of two integers (they must be integers). For example:
print(math.random(5, 10)) -- > Some random number between 5 and 10 print(math.random(10)) -- > Some random number between 1 and 10 (if no minimum range is given, it defaults to 1).
I assume you want rotation in degrees, in which case you'd apply the same logic:
math.random(0, 360)
Hope this helped, let me know if you have any questions.
math.randomseed(tick()*wait()) -- Ok, so this is basically setting up a seed for the randomizer. Without setting a seed chances are that you're going to end up with the same randomized result each time you test. This is just multiplying tick by wait to get a very random seed. local function randomizeNumbers(numOne, numTwo) local one, two = numOne or 0, numTwo or 100 -- So, if you leave numOne and numTwo blank (nil) then it will auto set numOne to 0 and numTwo to 100. return math.random(numOne, numTwo) end print(randomizeNumbers(0, 100)) -- This will print a random number from 0 to 100 print(randomizeNumbers(0, 100)) -- This will print another random number from 0 to 100 -- So, in conclusion you can now use the function randomizeNumbers (as long as it's defined above) to randomize two numbers specified. print(randomizeNumbers(1,500)) -- This will print a random number from 1 to 500
Hope I helped! :)