I'd like to generate unique random strings with Python, so I'm leveraging uuid4.
from uuid import uuid4
def generate_random_string():
return uuid4().hex
The problem is that it generates strings with too many characters. One possible solution that I came up with is to convert the string from base 16 to base 62 (digits + lowercase/uppercase letters). It works, but the result still has too many characters (22 to be more precise). Something between 6 and 10 chars would be great, but I'm afraid they might not be unique some time in the future. Is there any way to overcome this?