tcjennings / LUA-RFC-4122-UUID-Generator

Pure Lua Implementation of RFC 4122-compliant v4 pseudorandom UUID generator. Also includes an RFC 4122-compliant v5 SHA1-based UUID generator (bring your own crypto library). Both modules use the same license as Lua (the MIT license).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uuid4 generator uuid reduplicate in nginx

zhaojp0411 opened this issue · comments

at same time

Well I guess fix is to use http://wiki.nginx.org/HttpLuaModule#init_by_lua to create global uuid4 object and use it for generating all uuids, because of problems described in http://lua-users.org/wiki/MathLibraryTutorial "math.random , math.randomseed" section.

init_by_lua 'uuid4 = require "uuid4"';

Thanks for that comment, @intarstudents. I'm not familiar with nginx's lua capabilities but generally the uuid4 will get a time-based seed when the module first loads; implementors are encouraged to use better sources of random seeds if they have them. Loading a module once (as described by @intarstudents's) is better than loading it many times.