Open ivahaev opened 2 years ago
@ivahaev if using openresty, may I suggest you use https://github.com/thibaultcha/lua-resty-jit-uuid instead?
With this function your library works like a charm in OpenResty :).
timebased randomseeds are bad in general, this lib uses it because it is Lua only. With Openresty there are way better options, like the lib mentioned above they can use crypto grade seeds.
And even then, the state kept in the random generator is application global. So the application is responsible to manage that state. With Openresty it means seeding on init
and again on init-worker
. Calling this new seedonce
function on every call before getting a random number is not efficient.
In Kong we even report attempts to re-seed the random generator, so we can track them down and fix the underlying problem (see https://github.com/Kong/kong/blob/master/kong/globalpatches.lua#L256-L260)
@ivahaev if using openresty, may I suggest you use https://github.com/thibaultcha/lua-resty-jit-uuid instead?
Hmm. Just looked at lua-resty-jit-uuid
and it uses the exact same seed
function as this library.
I use uuid library for generating UUIDs, but each second we got the same UUIDs. Unfortunately I can't add
uuid.seed()
call intoinit_worker
context, so I wroteuuid.seedonce()
function which controls if it was called before and seeds only on the first call.