Yes there is, depending how your code works.
You have a table:
Code: Select all
table = {
["item1"] = 10,
["item2"] = 5,
["item3"] = 20,
...
}
But question is, is the amount of "itemx" the same, or does it keep changing during the program too?
Suppose it is stable, then you can have two different tables that keep track of same thing:
Code: Select all
Table = {like above}
Helptable = { "item1", "item2", "item3"}
Now you can do following:
Code: Select all
Rand = Rnd( TableItems(helptable) )
key = helptable[Rand]
debugprint( Table[key] )
and you are getting the value you are after.
If amount of "itemx" keep changing, then you need to remember to update that helptable as well. Good thing however is that if you are looking for random value among all the "item"s, then you dont need to worry that table and helptable have them in same order, as it doesnt really matter which "itemx" it happens to pick as long as it is random and exists. And do remember, if you remove one "itemx" from your table, you need to remove that from helptable as well, or you might be trying to access non existing table item.