Mercurial > wow > momit-suicide-kings
diff Utility.lua @ 3:a55f4f2a4603 tip
intial (real) commit!
author | Kyle@Kyle-PC |
---|---|
date | Thu, 23 Feb 2012 00:34:43 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utility.lua Thu Feb 23 00:34:43 2012 -0500 @@ -0,0 +1,48 @@ +--[[ +Title: Suicide Kings +Author: Brom +Version: 0.1 +]] + +local function RandomCharacter() + + -- 0-9, A-Z, a-z = 10 + 26 + 16 + local i = math.random(0,61) + + -- strip offset and ascii jump + if ( i >= 36 ) then + -- a:z + i = ( i - 36 ) + 97 + elseif ( i >= 10 ) then + -- A:Z + i = ( i - 10 ) + 65 + else + -- 0:9 + i = ( i + 48 ) + end + + return string.char( i ) + +end + +function SuicideKings:UID( reserved ) + + -- uid length + -- unique values = 62^4 = 14776336 + local length = 4 + + -- generate a random string + local s = RandomCharacter() + for i = 1, length-1 do + local c = RandomCharacter() + s = s .. c + end + + -- if taken, try again + while ( reserved[s] ~= nil ) do + s = SuicideKings:UID( reserved ) + end + + return s + +end \ No newline at end of file