lua生成uuid

来源:互联网 发布:司法考试音频加速软件 编辑:程序博客网 时间:2024/05/18 00:27

lua在linux环境下生成uuid

function CreateUUID()    local template ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"    d = io.open("/dev/urandom", "r"):read(4)    math.randomseed(os.time() + d:byte(1) + (d:byte(2) * 256) + (d:byte(3) * 65536) + (d:byte(4) * 4294967296))    return string.gsub(template, "x", function (c)          local v = (c == "x") and math.random(0, 0xf) or math.random(8, 0xb)          return string.format("%x", v)          end)endprint(CreateUUID())[参考](http://lisux.me/lishuai/?p=754)