INNER CODE UNIT · Python
gen_random_password
CYBERGEM777/HIDEAGEM · extras/ComfyUI/HIDEAGEM_NODES.py:273
def gen_random_password(bits_of_entropy: int) -> str:
"""
Generates a random password using a base62 character set (A-Z, a-z, 0-9) with a minimum length necessary to satisfy the given bits of entropy.
Parameters:
bits_of_entropy (int): The target bits of entropy.
Returns:
str: The generated random password.
"""
# Define the base62 character set
base62_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
# Calculate the entropy per character for the base62 set
entropy_per_char = math.log2(len(base62_charset))
# Calculate the minimum password length needed to achieve the target entropy
min_length = math.ceil(bits_of_entropy / entropy_per_char)