1. 程式人生 > >Python隨機字符串驗證碼

Python隨機字符串驗證碼

span color 生成 ret blog rand post div clas


def code_get(self): source = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] #數字驗證碼 # source = [ ‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘, ‘G‘, ‘H‘,‘I‘,‘J‘, ‘K‘,‘L‘, ‘M‘, ‘N‘,‘O‘,‘P‘,‘Q‘,‘R‘, # ‘S‘, ‘T‘, ‘U‘, ‘V‘, ‘W‘, ‘Z‘,‘X‘, ‘Y‘] #字母驗證碼 return ‘‘.join(random.sample(source, number)) #
number是生成驗證碼的位數

Python隨機字符串驗證碼