For a project, I need a method of creating thousands of random strings while keeping collisions low. I’m looking for them to be only 12 characters long and uppercase only. Any suggestions?
Advertisement
Answer
CODE:
JavaScript
x
5
1
from random import choice
2
from string import ascii_uppercase
3
4
print(''.join(choice(ascii_uppercase) for i in range(12)))
5
OUTPUT:
5 examples:
JavaScript
1
6
1
QPUPZVVHUNSN
2
EFJACZEBYQEB
3
QBQJJEEOYTZY
4
EOJUSUEAJEEK
5
QWRWLIWDTDBD
6
EDIT:
If you need only digits, use the digits
constant instead of the ascii_uppercase
one from the string
module.
3 examples:
JavaScript
1
4
1
229945986931
2
867348810313
3
618228923380
4