Skip to content

Instantly share code, notes, and snippets.

@zenweasel
Created April 20, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenweasel/d4d359d768063558c7f3 to your computer and use it in GitHub Desktop.
Save zenweasel/d4d359d768063558c7f3 to your computer and use it in GitHub Desktop.
Create random characters for password
import random
def _create_random_password(num_chars):
"""
Create a string of random characters
:param num_chars:
:return:
"""
password_string = ''
seed = string.ascii_letters + string.digits + string.punctuation
seed_len = len(seed) - 1
for x in range(0, num_chars):
rnd = int(random.uniform(0, seed_len))
random_char = seed[rnd:rnd+1]
password_string += random_char
return password_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment