Created
June 2, 2014 03:14
-
-
Save gnrfan/7f6b7803109348e30c8f to your computer and use it in GitHub Desktop.
Base62 UUID based on uuid.uuid4() and a numbers, lowercase, uppercase alphabet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
import hashlib | |
import baseconv | |
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
def base62uuid(): | |
converter = baseconv.BaseConverter(ALPHABET) | |
uuid4_as_hex = str(uuid.uuid4()).replace('-','') | |
uuid4_as_int = int(uuid4_as_hex, 16) | |
return converter.encode(uuid4_as_int) | |
if __name__ == '__main__': | |
print base62uuid() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my version of this: