lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Sunshilong.

On Sun, Oct 11, 2020 at 1:41 PM 孙世龙 sunshilong <sunshilong369@gmail.com> 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.

Francisco Olarte.