Mercurial > wow > momit-suicide-kings
comparison Utility.lua @ 3:a55f4f2a4603 tip
intial (real) commit!
author | Kyle@Kyle-PC |
---|---|
date | Thu, 23 Feb 2012 00:34:43 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:37321677b4d9 | 3:a55f4f2a4603 |
---|---|
1 --[[ | |
2 Title: Suicide Kings | |
3 Author: Brom | |
4 Version: 0.1 | |
5 ]] | |
6 | |
7 local function RandomCharacter() | |
8 | |
9 -- 0-9, A-Z, a-z = 10 + 26 + 16 | |
10 local i = math.random(0,61) | |
11 | |
12 -- strip offset and ascii jump | |
13 if ( i >= 36 ) then | |
14 -- a:z | |
15 i = ( i - 36 ) + 97 | |
16 elseif ( i >= 10 ) then | |
17 -- A:Z | |
18 i = ( i - 10 ) + 65 | |
19 else | |
20 -- 0:9 | |
21 i = ( i + 48 ) | |
22 end | |
23 | |
24 return string.char( i ) | |
25 | |
26 end | |
27 | |
28 function SuicideKings:UID( reserved ) | |
29 | |
30 -- uid length | |
31 -- unique values = 62^4 = 14776336 | |
32 local length = 4 | |
33 | |
34 -- generate a random string | |
35 local s = RandomCharacter() | |
36 for i = 1, length-1 do | |
37 local c = RandomCharacter() | |
38 s = s .. c | |
39 end | |
40 | |
41 -- if taken, try again | |
42 while ( reserved[s] ~= nil ) do | |
43 s = SuicideKings:UID( reserved ) | |
44 end | |
45 | |
46 return s | |
47 | |
48 end |