local damage = tool:WaitForChild'Damage'.Value local maxDamage = tool:WaitForChild'MaxDamage'.Value damageCal = math.random(damage,maxDamage) print(damageCal) print(damageCal)
just in case you were wondering the values damage is 5 and the value for max damage is 10
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:
-- This is probably most conveniently written at the beginning of your script math.randomseed(os.time()) -- Print a random number between 1 and 10 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) -- Constant seed -- Print a random number 1 through 10, five times 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.