生成6位的隨機驗證碼


要求:生成6位的字母和數字組成的隨機驗證碼。

實例1:

 1 import random
 2 identify_code=''
 3 for i in range(1):
 4     for j in range(6):
 5         if i==j:
 6             code=chr(random.randint(65,90))
 7         else:
 8             code=random.randint(0,9)
 9         identify_code+=str(code)
10 
11 print(identify_code)

實例2:

 1 import random
 2 checkcode=''
 3 for i in range(6):
 4     current=random.randrange(0,4)
 5     if current!=i:
 6         temp=chr(random.randint(65,90) or random.randint(97,122))
 7     else:
 8         temp=random.randint(0,9)
 9     checkcode+=str(temp)
10 print(checkcode)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM