Skip to content

Instantly share code, notes, and snippets.

@bmacauley
Last active December 31, 2015 14:12
Show Gist options
  • Select an option

  • Save bmacauley/5309589 to your computer and use it in GitHub Desktop.

Select an option

Save bmacauley/5309589 to your computer and use it in GitHub Desktop.
# coding: utf-8
def to_base(q, alphabet):
if q < 0: raise ValueError, "must supply a positive integer"
l = len(alphabet)
converted = []
while q!= 0:
q, r = divmod(q, l)
converted.insert(0, alphabet[r])
return "".join(converted) or '0'
to_base( hash(str(uuid.uuid1())) % 100000000,
'0123456789abcdefghijklmnopqrstuvwxyz') )
to_36(q):
return to_base(hash(str(uuid.uuid1())) % 100000000, '0123456789abcdefghijklmnopqrstuvwxyz') )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment