Files
cultivation-world-simulator/src/utils/id_generator.py
2025-09-02 00:35:07 +08:00

21 lines
462 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
简化的ID生成器替代UUID4
"""
import random
import string
def base62_id(length: int = 8) -> str:
"""
生成base62编码的短ID数字+大小写字母)
默认8位比UUID4的36位短很多
"""
charset = string.ascii_letters + string.digits # 0-9, a-z, A-Z (62个字符)
return ''.join(random.choices(charset, k=length))
def get_avatar_id() -> str:
"""获取Avatar ID的默认函数"""
return base62_id(8)