Random password generator with python

--

Photo by rc.xyz NFT gallery on Unsplash

This is how to create a very simple python program to generate a random password.

Check out the code below

import randomcharacters = 'abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVXYZ!@#$&1234567890'char_len = len(characters)k = int(input("How many characters do you need? : "));password = ''def gen_pswd():  global k, password  while (k > 0):     password = password + (characters[random.randint(0,char_len)])     k = k-1  return (password)print("Suggested password is",gen_pswd())

In order to get a random integer to application, should import ‘random’ module to app.

More characters can be added to ‘characters’ string.

randint(a,b) returns a random integer within a given range.

--

--

Dilshanka Liyanage
Dilshanka Liyanage

Written by Dilshanka Liyanage

Full-Stack Web Developer, Passionate Learner, Gopher, Typescript, AWS, and SQL in my circle and I play chess

No responses yet