Math.random() and decimal values

Ok so here’s the basic rundown.


I’ve got this super cool equation the server does for calculating damage and stuff. On the highlighted line I wanted to put math.random(1, 1.125) so that way the damage values could be a little varied and stuff.

However I noticed that for some silly reason all of the damage values are the same no matter what.
image

The damage I’m getting right now means that it’s always multiply the players STR stat by 1, but I’m trying to get it to do anything between 1 and 1.125 and it’s just not doing that
(Damage value if I remove math.random() and replace it with just 1.125)
image

So yeah I’m a little stumped right here. Any help would be appreciated
image

use nextnumber

local RNG = Random.new()

print(RNG:NextNumber(1,1.125))
2 Likes

Math.random only returns integers. (whole numbers)

local DecimalMult = 100 --10 = 0.1, 100 = 0.01, etc.
local RandRange = {1, 1.25} --The range of math.random

for i, Num in RandRange do
RandRange[i] *= DecimalMult
end
local RandNum = math.random(table.unpack(RandRange))/DecimalMult

This should solve it while still using math.random assuming that’s what you prefer.
DecimalMult changes how many numbers past the decimal point are allowed. Think of it as dividing by tens.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.