"" White Time: January 8, 2018 function : generates a random 4-bit verification code (must consist of two 2 letters and 2 digits) "" "Import randomdef main (): list_num = [1,2,3,4,5,6,7,8,9,0] list_str = [' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G ', ' H ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' s ', ' t ', ' x ', ' y ', ' z '] veri_str = Random.sample (list_str,2) veri_num = random.sample (list_num,2) veri_out = random.sample (veri_num + veri_str,4) veri_ Res = str (Veri_out[0]) + str (veri_out[1]) + str (veri_out[2]) + str ( VERI_OUT[3]) print (veri_res) if __name__ == ' __main__ ': main ()
Here are two questions:
1, how to simplify the list_str to generate a A-Z list, here I use a more stupid method of one column out
2, do not know Python has no one-click function, generate a verification code of the kind
If you know the above two questions, please leave a message to tell me, greatly appreciated! ~
Generate random 4-bit verification codes with Python