您的位置:首页 > 编程语言 > Lua

在lua中正确使用uuid的方法:

2015-05-07 20:54 302 查看
-- 参考:http://ju.outofmemory.cn/entry/97724
local function guid()
local template ="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
local 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.upper(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
))
end

local file_id =  guid();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: