How do I get a random number with a decimal?

math.random() doesn’t work,
Random.new():NextNumber() does work but how would I limit this to only numbers like 1.34 (2 decimals)?

1 Like

You can try something like this:


local decimals = 100
local min = 0
local max = 10
local num = math.random(min * decimals, max * decimals)
num = num / decimals
local num = Random.new():NextNumber()
local decimalPlaces = 2
result = math.floor(num*10^decimalPlaces)/(10^decimalPlaces)

This will get the number you want, assuming ‘num’ is the number you got from :NextNumber() and ‘decimalPlaces’ is the number of decimal places you want in the result.

1 Like