ImportRandomdefCode (n=6,alpha=True): s="' #Create a string variable to store the generated verification code forIinchRange (N):#Verify the number of code bits with a for loop controlnum = Random.randint (0,9)#generate random number 0-9 ifAlpha#requires the letter verification code, does not have the argument, if does not need the letter, the keyword Alpha=falseUpper_alpha = Chr (Random.randint (65,90)) Lower_alpha= Chr (Random.randint (97,122) Num=Random.choice ([Num,upper_alpha,lower_alpha]) s= S +str (num)returnsPrint(Code (6,FALSE))#Print 6 digit verification CodePrint(Code (6,TRUE))#Print 6-digit mixed-letter verification CodePrint(Code (4,FALSE))#Print 4 digit verification CodePrint(Code (4,TRUE))#Print 4-digit mixed-letter verification Code
The above code for reference only, there are questions can leave a message, communicate with each other!
Randomly generated six-bit code function version (Python)