Hello, I want to generate string with N size.
It should be made up of numbers and upper case english letters such as:
- 6U1S75
- 4Z4UKK
- U911K4
How can I achieve this in a pythonic way ?
Thanks
Hello, I want to generate string with N size.
It should be made up of numbers and upper case english letters such as:
How can I achieve this in a pythonic way ?
Thanks
''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
Taking the answer from Ignacio, this works with python 2.6:
import random
import string
N=6
print ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
Example output: JQUBT2
e.g.
import random
import string
char_set = string.ascii_uppercase + string.digits
print ''.join(random.sample(char_set,6))