Generating Random strings using Python

Hi,

Just wanted to share a very small implementation of generating random string values for a range of 6 chars, I am actually working on creating a hashing of the keys for some authentication module. I will share the same implementation soon for that Keep watching :).

Just for now have a look on this. Hope this helps some one out there.

import random
import string

def genearateRandomStrings():

//creates a combination of chars
chars=string.ascii_lowercase + string.ascii_uppercase

//now using the random module functions and list comprehension generate a set of random strings.
return ”.join(random.choice(chars) for x in range(6))

print genearateRandomStrings()

//OUTPUT
HjuKLY

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s