Is there a way to get a random decimal number?

Hi I want to get a random number between -0.5 and 0.5
I tried using math.random() but it returned 0

here is an example

local spread = 0.5

local function shoot()
   -- my code
   local x = math.random(-spread, spread)
   local y = math.random(-spread, spread)
   print(x .. " / " .. y) -- prints "0 / 0" in the output

Can look here: Random (
The :NextNumber(min, max) method may work for what you need.
Can also just subtract 0.5 from what’s returned by math.random() ← no args

1 Like

math.random only gives you whole numbers if you have arguments, so you can just get a random number between -500 and 500 and then divide that by 100, and you can also choose how many decimals to get by increasing or decreasing the zeros