I want to generate a string of size N.
It should be made up of numbers and uppercase English letters such as:
- 6U1S75
- 4Z4UKK
- U911K4
How can I achieve this in a pythonic way?
I want to generate a string of size N.
It should be made up of numbers and uppercase English letters such as:
How can I achieve this in a pythonic way?
You can use the code
This will random spit out a random 7 alphanumeric pattern, simply change the 7 to any number you wish and it will produce that many numbers and/or letters.
Another way to write this is as follows...
I am unsure of how to add restrictions such as making it to where it does not allow certain numbers and/or letters to be next to each other or repeat such as getting "AAA123" if anyone knows how to restrict the outcome to have something like this please comment back
Based on another Stack Overflow answer, Most lightweight way to create a random string and a random hexadecimal number, a better version than the accepted answer would be:
much faster.
for python 3 import string, random
''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(15))