Module:Guid: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
(guid)
 
(maybe each module needs to set the seed?)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
function guid()
local p = {}
 
function p.seed()
  math.randomseed( tonumber( tostring( os.time() ):reverse():sub( 1, 6 ) ) )
end
 
function p.new()
   local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
   local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
   local g = string.gsub( template, '[xy]', function ( c )
   local g = string.gsub( template, '[xy]', function ( c )
Line 8: Line 14:
end
end


return guid
return p

Latest revision as of 00:30, June 24, 2020

Documentation for this module may be created at Module:Guid/doc

local p = {}

function p.seed()
  math.randomseed( tonumber( tostring( os.time() ):reverse():sub( 1, 6 ) ) )
end

function p.new()
  local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
  local g = 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)
  return g
end

return p