31 lines
778 B
Python
31 lines
778 B
Python
import random
|
|
import string
|
|
import time
|
|
|
|
|
|
def get_random_num_code(length=8):
|
|
return "".join(random.choices(string.digits, k=length))
|
|
|
|
|
|
def get_random_letter_code(length=8):
|
|
return "".join(random.choices(string.ascii_lowercase, k=length))
|
|
|
|
|
|
def get_random_letter_and_num_code(length=4):
|
|
return ''.join(random.sample(string.ascii_letters + string.digits, length))
|
|
|
|
|
|
def time_now_to_code():
|
|
milliseconds = int(round(time.time() * 1000)) + random.randint(1000, 300000)
|
|
BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
if milliseconds == 0:
|
|
return '0'
|
|
|
|
result = ''
|
|
while milliseconds > 0:
|
|
remainder = milliseconds % 62
|
|
result = BASE62[remainder] + result
|
|
milliseconds //= 62
|
|
|
|
return result
|