last around 2320

This commit is contained in:
Kar
2025-04-02 19:19:22 +05:30
parent af3da2e42a
commit 52cf992677
4 changed files with 102 additions and 0 deletions

20
siliconid.py Normal file
View File

@@ -0,0 +1,20 @@
import time
import random
BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
def to_base62(num):
result = ""
while num > 0:
result = BASE62[num % 62] + result
num //= 62
return result
def generate_id():
epoch_start = int(time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, 0))) * 1000
now = int(time.time() * 1000) - epoch_start
random_num = random.randint(0, 999) # 3-digit random number
id_num = now * 1000 + random_num # Combine timestamp + randomness
return to_base62(id_num).zfill(8)[:8] # Ensure 8 chars
print(generate_id()) # Example output: "8F2T5MkQ"