random password generator python code example

Example 1: random letter generator python

import random
import string
random.choice(string.ascii_letters)

Example 2: password generator python

import string
from random import *
characters = string.ascii_letters + string.punctuation  + string.digits
password =  "".join(choice(characters) for x in range(randint(8, 16)))
print password

Example 3: python password generator

import random
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@£$%^&*().,?0123456789'

number = input('Please enter a number of passwords.')
try:
    number = int(number)
except:
    print("Error, please enter a number!")

length = input('Length of password?')
try:
    length = int(length)
except:
    print("Error, please enter a number!")

print('\nHere are your password(s):')

for pwd in range(number):
  password = ''
  for c in range(length):
    password += random.choice(chars)
  print(password)

Example 4: python random string

import secrets 
secrets.token_hex(nbytes=16)

# this will produce something like 
# aa82d48e5bff564f3221d02194611c13

Example 5: python random password generator

import random

alph = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ\
             abcdefghijklmnopqrstuvwxyz\
             1234567890 !@#$%^&*(){}[]<>,.')
out = ''
for char in string:
    out += random.choice(alph)
    
print(out)

Example 6: how to create a password generator in python

#Simple Way To Make Password Generator
import random

chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@€$#%({)}],/<\.>[*^&"

while 1:
    password_len = int(input("What length would you like your password to be ? :"))
    password_count = int(input("How many passwords would you like ? "))
    for x in range(0, password_count):
        password = ""
        for x in range(0,password_len):
            password_char = random.choice(chars)
            password      = password + password_char
        print("Here is your password : ",password)