I am trying to randomly choose a key from a table then also randomize a value from that random key.
Example Table
items = {
["Rock"] = {min = 1, max = 5},
["Sand"] = {min = 4, max = 12},
["Glass"] = {min = 20, max = 45},
}
Then this function
function printTable()
local keys = {}
for k,v in pairs(items) do
table.insert(keys, k)
local keys = keys[math.random(1, #keys)]
local amount = math.random(v.min,v.max)
print(item, amount)
end
end
It prints a random key, with its values, but then it prints more random keys with less values that don't go with it.
What i am looking to do is, print one of the keys then only the values for said key so,
Sand 6
or
Glass 31
So on so fourth.
Any help would be awesome!
item
, amount) rather thenk
. after changing that i got your desired output. Rock 3 Sand 11 Glass 32. Also your method of randomly retrieving an item may not be as random as you would likemath.randomseed()
to make truly random numbers