Skip to content

Instantly share code, notes, and snippets.

@dangh
Forked from jrus/lua-uuid.lua
Last active April 6, 2023 09:52
Show Gist options
  • Save dangh/6688fd90ac519b72200f2f1353f43ecc to your computer and use it in GitHub Desktop.
Save dangh/6688fd90ac519b72200f2f1353f43ecc to your computer and use it in GitHub Desktop.
quick lua implementation of "random" UUID
local function uuid()
math.randomseed(os.time())
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment