Python to Generate Recursive Random Password with Full Source Code For Beginners

Generates a random password with the length specified using recursivity.

Run the Script:

python3 generator.py
Code language: CSS (css)

Source Code:

generator.py

import random import string def stretch(text,maxlength): if len(text) < maxlength: randomChar = get_random_char() return stretch(text+randomChar,maxlength) else: return text def get_random_char(): chars = string.printable randomChar = chars[random.randint(0,len(chars)-1)] return randomChar while 1: maxlen = input(' [?] Enter a length for your password (e for exit): ') try: maxlength = int(maxlen) print("'",stretch('',maxlength),"'\n") except: if maxlen == 'e': break print('Please Enter an integer')
Code language: PHP (php)

Output:

Leave a Comment