Generate random 4-bit verification codes with Python

Source: Internet
Author: User

""             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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.