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


for project, need method of creating thousands of random strings while keeping collisions low. i'm looking them 12 characters long , uppercase only. suggestions?

code:

from random import choice string import ascii_uppercase  print(''.join(choice(ascii_uppercase) in range(12))) 

output:

5 examples:

qpupzvvhunsn efjaczebyqeb qbqjjeeoytzy eojusueajeek qwrwliwdtdbd 

edit:

if need digits, use digits constant instead of ascii_uppercase 1 string module.

3 examples:

229945986931 867348810313 618228923380 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -