mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
add base62
This commit is contained in:
parent
d52b2d4801
commit
14f7c366d0
1 changed files with 7 additions and 3 deletions
|
@ -191,16 +191,20 @@ def maxID(db):
|
||||||
"select max(id) from %s" % tbl))
|
"select max(id) from %s" % tbl))
|
||||||
return now + 1
|
return now + 1
|
||||||
|
|
||||||
def base91(num):
|
# used in ankiweb
|
||||||
|
def base62(num, extra=""):
|
||||||
s = string
|
s = string
|
||||||
# all printable characters minus quotes, backslash and separators
|
table = s.letters + s.digits + extra
|
||||||
table = s.letters + s.digits + "!#$%&()*+,-./:;<=>?@[]^_`{|}~"
|
|
||||||
buf = ""
|
buf = ""
|
||||||
while num:
|
while num:
|
||||||
num, i = divmod(num, len(table))
|
num, i = divmod(num, len(table))
|
||||||
buf = table[i] + buf
|
buf = table[i] + buf
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
def base91(num):
|
||||||
|
# all printable characters minus quotes, backslash and separators
|
||||||
|
return base62(num, "!#$%&()*+,-./:;<=>?@[]^_`{|}~")
|
||||||
|
|
||||||
def guid64():
|
def guid64():
|
||||||
"Return a base91-encoded 64bit random number."
|
"Return a base91-encoded 64bit random number."
|
||||||
return base91(random.randint(0, 2**64-1))
|
return base91(random.randint(0, 2**64-1))
|
||||||
|
|
Loading…
Reference in a new issue