Math.random not randomising between 2 numbers from a table

I’m trying to get a random number between the 2 numbers in the table but it always ends up either returning the first number in the table or the last number in the table while i want it to get a random number in between the 2 numbers in the table

image

I’ve tried

my code

local tool = script.Parent
local gui = tool:WaitForChild("Gui")
local handle = tool:WaitForChild("Handle")

local valueTable = {
	["None"] =     {0.00, 0.00},
	["Normal"] =   {0.90, 2.00},
	["Critical"] = {2.15, 5.00},
	["Lethal"] =   {5.25, 8.00},
}

local soundTable = {
	["Normal"] = handle.Normal,
	["Critical"] = handle.Critical,
	["Lethal"] = handle.Lethal,
}

local function updateValue(newValue, gui)
	radNumber = math.random(valueTable[newValue][1], valueTable[newValue][12])
	gui.Frame.RadiationValue.Text = radNumber.." SV/h"
	gui.Frame.Status.Text = newValue
	for i, v in pairs(soundTable) do
		if i == newValue then
			v.Playing = true
		else
			v.Playing = false
		end
	end
end

task.spawn(function()
	wait(1)
	while true do
		updateValue(game.Players.LocalPlayer:GetAttribute("RadLevel"), gui)
		task.wait(5)
	end
end)

I think you mean 2 overhere, it maybe a typo.

math.random only work with integers
you can use Random.new():NextNumber(tbl[1], tbl[12])

or do this if u want to use math.random although Random.new()NextNumber() is recommended incase the number is too small

math.random(valueTable[newValue][1] * 100, valueTable[newValue][12] * 100) / 100

also valueTable[newValue][12] doesn’t exist in the table

Yes it is a typo but still it doesn’t work

Random.new():NextNumber(tbl[1], tbl[12])

worked, thanks!

1 Like