+ 2

How do u create a random word generator?

Like for example a password generator that gives out random inputs in python searched for such topic but didn't quite find what i have wanted as an answer.

18th Aug 2023, 10:32 AM
Adam Raafat
Adam Raafat - avatar
3 Answers
+ 1
Adam Raafat , I have some hints for you to get started: - Use the random module, and then make a string variable that stores all characters you needed to generate password, then make a empty string variable. - You can use random.randint method to get a random integer, which can be used to specify the length of the password, or just specify the password length yourself. first parameter is minlength, while the second is the maxlength. Run a for(or while) loop N times, where N is the length of password, add the X, where X is the character generated randomly in the password variable, which is something like: n[random.randint(0,n.length)], to the empty string. There you go! Code example(PLEASE ONLY READ IT!): import random password = "abcdefghijklmnopqrstuvwxyz123456789@&#*^^" a = "" length = random.randint(8,16) while len(a) != length: a+=password[random.randint(0,len(password))] print(a)
18th Aug 2023, 11:40 AM
Dragon RB
Dragon RB - avatar
+ 1
thanks! although i cannot understand the a+= part clearly but i will figure it thanks though.
18th Aug 2023, 1:46 PM
Adam Raafat
Adam Raafat - avatar
+ 1
Adam Raafat a+= ... is the same as a = a+... it works for other math operator too, such as -= for subtraction, *= for multiplication, /= for division
18th Aug 2023, 1:50 PM
Dragon RB
Dragon RB - avatar