Aug-23-2022, 06:45 PM
Another way of doing it
# Do the imports from random import sample, shuffle import string # define the function def generate_id(): ''' Get the needed sample characters and size using string ''' small_letters = sample(string.ascii_lowercase, 4) capital_letters = sample(string.ascii_uppercase, 2) numbers = sample(string.digits, 2) special_characters = sample('_+-!', 2) # Combine and shuffle samples result = small_letters + capital_letters + numbers + special_characters shuffle(result) # Return the results return ''.join(result) for i in range(5): print(generate_id())
Output:+Gr5-pgN2u
cgOh4-2Gq+
6F!Xi+ztw7
+xb3Z1Gvp-
mF7!h_snG5
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts