Skip to content
Advertisement

What’s the best way to generate random strings of a specific length in Python?

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

OUTPUT:

5 examples:

JavaScript

EDIT:

If you need only digits, use the digits constant instead of the ascii_uppercase one from the string module.

3 examples:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement