Generate passwords with high randomness in a simple way
Generate random passwords with only 20 lines of code
Core idea: use random module
The random module generates random numbers, upper and lower case letters, and loop times.
while loop + number of randomly generated loops --> random plus++
Upper case ASKII codes between 65-90
Lowercase Askll codes between 97-122
Final result: x uppercase letters + y numbers + z lowercase letters (x, y, z are randomized)
Randomness is improved over the old monotonous lowercase+numbers+uppercase+lowercase+numbers+uppercase... loop
import random print("Random number generation”) time=(1,2) while time: time1=(1, 3) time2=(1, 2) time3=(1, 3) while time1: a= (65,90) print("%c"%a,end="") time1-=1 while time 2: c= (0,99) print("%d"%c,end="") time2-=1 while time3: b= (97,122) print("%c"%b,end="") time 3-=1 time-=1
ADDITIONAL: Generate a random six-digit CAPTCHA (CAPTCHA consists of numbers and letters (upper and lower case letters)) using Python
import random 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 Here's where therandomRandomly generating an interval integer in the function randint function module This is the first time I've learned that loops can be used in this way for _ in range(): hhh 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 def generate_code(code_len = 6): all_char = '0123456789qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJIKOLP' index = len(all_char) + 1 code = '' for _ in range(code_len): num = (0,index) code += all_char[num] return code print(generate_code())
summarize
The above is a small introduction to python randomly generated mixed upper and lower case alphanumeric password (only 20 lines of code), I hope to help you!