Generate short database identifier names from an integer
The trick is to find a formula for where a new place has to be added. In this case the formula is:

$$ d_k = 26*(36^k-1)/35 $$

If n >= dk then the name of n has at least k+1 digits.

The turnover points are 26, 962, 34658, 1247714, ...

name 24          = y
name 25          = z
name 26          = aa
name 27          = ab

name 960         = z8
name 961         = z9
name 962         = aaa
name 963         = aab

name 34656       = z98
name 34657       = z99
name 34658       = aaaa
name 34659       = aaab

name 1247712     = z998
name 1247713     = z999
name 1247714     = aaaaa
name 1247715     = aaaab

name 44917728    = z9998
name 44917729    = z9999
name 44917730    = aaaaaa
name 44917731    = aaaaab


After finding k, just represent n - dk as a k+1 digit number base 36.

Some Python code:

theChars = "abcdefghijklmnopqrstuvwxyz0123456789"

# the magic formula:
def dk(k):
  return (26 * (36**k-1)) / 35 

def name(n):
  # find the largest k s.t. dk(k) &lt;= n
  k = 0
  while dk(k) &lt;= n:
    k += 1
  k -= 1
  # take k+1 digits mod 36
  q = n - dk(k)
  digits = ""
  while k &gt;= 0:
    r = q % 36
    q = q / 36
    digits = digits + theChars[r]
    k -= 1
  return digits[::-1]  # shortcut to reverse a string

def testForDuplicates(a,b):
  seen = set()
  for n in xrange(a,b):
    m = name(n)
    if m in seen:
      print "duplicate found at n =", n, ", name:", m
    seen.add(m)

def printRange(a,b):
  for n in xrange(a,b+1):
    print n, " -&gt;", name(n)

printRange(20,30)
printRange(955,965)
printRange(34650,34662)
printRange(1247710,1247720)
printRange(44917727,4491773)

testForDuplicates(0,1000000) # takes about 6 secs