How to get a random dictionary in a table without a different table?

local countries = {
    ["oi"] = {
        ["Currency"] = "U$";
        ["Ranking"] = 2;
        ["StartingMoney"] = 1500
    };
    ["Hiii"] = {
        ["Currency"] = "HK$";
        ["Ranking"] = 2;
        ["StartingMoney"] = 500
    };
    ["hello"] = {
        ["Currency"] = "UB$";
        ["Ranking"] = 2;
        ["StartingMoney"] = 4500
    }
}

Now I don’t want make another table of arrays
like
local newtable = {"hi","hello","bruh"}
I want to get a random country name from the countries

But if I say print(countries[1]) it prints as nil

How do I get random country?

One way would be using the next() function like below:

local countries = -- that table

-- get the length of the table
local length = 0
for _,_ in pairs(countries) do length += 1 end

local function GetRandomValue(t, len)
	local key, value
	
	for i = 1, math.random(1, len) do
		if i == 1 then
			key, value = next(t) 
		else
			key, value = next(t, key)
		end
	end
	
	return key, value
end

-- then we can test the above function by just looping and getting random values
for i = 1, 10 do
	print(GetRandomValue(countries, length))
end

Creating an extra table might be more efficient not sure why you don’t want to use one