[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Could somebody explain "due to the way that Lua implements tables, the order that elements appear in a traversal is undefined" in more detpth?
- From: Francisco Olarte <folarte@...>
- Date: Sun, 11 Oct 2020 18:58:09 +0200
On Sun, Oct 11, 2020 at 1:41 PM 孙世龙 sunshilong <firstname.lastname@example.org> wrote:
> The sentence aforementioned is quoted from <<Programming in Lua>>(Page 38).
> Here is the sentence followed [emphasise mine]:
> The same program can **produce different orders each time it runs**.
> The only certainty is that each element will appear once during
> the traversal.
> Why the same program may produce different orders each time it runs?
I do not have the whole program handy, so I do not know the exact
answer. But if all the program does is fill a table and then traverse
it it may be due, typically, by randomization of hashes ( you generate
a random value at program/lua state start and use it in the generation
of hash values, a classical mitigation of denial of service attacks
similar to salting passwords ).
It may be due to other reasons. In general this hints you on not
relying on table enumeration order.