Skip to content

Instantly share code, notes, and snippets.

@sunnykrGupta
Forked from jaybaird/lua-uuid.lua
Created October 24, 2015 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnykrGupta/bc069183f80374971bc1 to your computer and use it in GitHub Desktop.
Save sunnykrGupta/bc069183f80374971bc1 to your computer and use it in GitHub Desktop.
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