Skip to content

Instantly share code, notes, and snippets.

@x5lcfd
Forked from jrus/lua-uuid.lua
Created October 20, 2017 08:24
Show Gist options
  • Save x5lcfd/335dbb3239e5518c4c63f9cd8a5ed225 to your computer and use it in GitHub Desktop.
Save x5lcfd/335dbb3239e5518c4c63f9cd8a5ed225 to your computer and use it in GitHub Desktop.
quick lua implementation of "random" UUID
local random = math.random
local function uuid()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and random(0, 0xf) or 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