- changed status to wontfix
Table.Random failing on unordered tables
Issue #27
wontfix
Code:
local tab = {};
--tab[1] = "hi2";
tab[2] = "hi";
rnd = Table.Random(tab);
say rnd;
This always crashes, because "rnd" is nil. It seems that "Table.Random" only works if the table is ordered. If you were to turn the commented line into actual code, it would work fine.
Comments (2)
-
-
If adding/removing to the list/sequence is a problem, remember that this is what the Table.Insert and Table.Remove functions are for. Find me on IRC tomorrow.
- Log in to comment
This is the intended behavior.
Table.Random works on the list part of the table. This is also mentioned in the documentation in the wiki on that function.
//edit: To clarify, the list part of the table is defined as follows in the language specification: