Small notice: I'm not on my laptop right now, and I'm currently using a computer at the library with a Godawful keyboard. So if I made some illegible typos, I appologize ahead of time.
Patterns
This is because the order in which math.random selects its numbers is entirely based off a seed. The "seed" in this case, is a number in which sets the path for a sequence of numbers that is deemed "random".
Why do you need to know this?
Well, there's actually a function you may or may not be aware of that can handle situations such as this in the math library, called math.randomseed. This function takes one argument, which is a number, and sets it as the RNG seed that defines what sequence the numbers turn up in.
How do I use math.randomseed?
Well as I said before, the random numbers are based off the seed. Same seed, same set of numbers. Which means if you want a truly random set of numbers each time, you're going to need a different seed each time. But what number can you use that's constantly changing...? Time!
You can simply use time that tick or os.time returns as the seed for the math.randomseed function, and that should suffice. Here's an example:
math.randomseed(os.time())
print(math.random(10))
This would be opposed to using a constant seed, where if I said something like this, we'd get the same set of numbers constantly:
math.randomseed(1)
for i = 1,5 do
print(math.random(10))
end
The code above should yield this result every time, the first time it's ran:
6
2
2
8
9
Anyway, hope that helped. Just let me know if you have any questions.
2 comments
Well, because of math.randomseed(). try putting a wait(1) infront of the math.random, and then you'll get something different. Or try it in the command bar
And it only makes damageCal once, it will print the same thing in those two prints