有個需求,須要僞造跟用戶行爲很是相似的帳號密碼,並且須要一個閥值控制僞造的數量。python
在這需求上,還有一個就是須要控制生成的比率、跳出率不能太高或者過低。git
對此就隨手用python寫了一個,bug不知道有木有,沒有測,具體有興趣能夠去改改。app
#coding:utf-8 import random class create_data: global zimu_xx,zimu_dx,number,teshu # 生成26個英文字母,大小寫 zimu_xx=[chr(i) for i in range(97,123)] zimu_dx=[chr(i).upper() for i in range(97,123)] # 生成隨機的數字範圍在(1-8000) number=[i for i in range(1,8001)] # 生成特殊字符串 teshu=['!','@','#','$','%','^','&','*','(',')','_','+','-','=','|','}','{','[',']',';','"',',','<','>','.','?','/'] def __init__(self): self.u_1=0 self.u_2=0 self.u_3=0 self.u_4=0 self.p_1=0 self.p_2=0 self.p_3=0 self.p_4=0 self.p_5=0 self.p_6=0 def username(self): # 隨機判斷標準 task=random.randint(0,10) # 結果列表 results_all=[] # 字母結果 results_letters=[] # 數字結果 results_digital=[] try: if (task>0 and task<3): self.u_1=self.u_1+1 while len(results_letters)<4: results_letters.append(random.choice(zimu_xx)) results_all.append("".join(results_letters)) while True: if random.choice(number)<1500: results_all.append(random.choice(number)) break else: continue return results_all[0].encode('utf-8')+str(results_all[1]) elif (task>3 and task<6): self.u_2=self.u_2+1 while len(results_letters)<5: results_letters.append(random.choice(zimu_xx)) results_all.append("".join(results_letters)) while True: if random.choice(number)>1500 and random.choice(number)<3000: results_all.append(random.choice(number)) break else: continue return results_all[0].encode('utf-8')+str(results_all[1]) elif (task>6 and task<9): self.u_3=self.u_3+1 while len(results_letters)<6: results_letters.append(random.choice(zimu_xx)) results_all.append("".join(results_letters)) while True: if random.choice(number)>3000 and random.choice(number)<6000: results_all.append(random.choice(number)) break else: continue return results_all[0].encode('utf-8')+str(results_all[1]) else: self.u_4=self.u_4+1 temp=[] while len(results_letters)<3: results_letters.append(random.choice(zimu_xx)) results_all.append("".join(results_letters)) while True: if random.choice(number)>6000 and random.choice(number)<8000: results_all.append(random.choice(number)) break else: continue while len(temp)<3: temp.append(random.choice(results_letters)) results_all.append("".join(temp)) return results_all[0]+str(results_all[1])+results_all[2] except IndexError,e: pass def passwd(self): # 隨機判斷標準 task=random.randint(0,15) # 結果列表 results_all=[] # 字母結果(大寫) results_letters_big=[] # 字母結果(小寫) results_letters_small=[] # 數字結果 results_digital=[] # 特殊字符 results_special_characters=[] try: if (task>0 and task<3): self.p_1=self.p_1+1 while len(results_letters_big)<3: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<3: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) while len(results_special_characters)<3: results_special_characters.append(random.choice(teshu)) results_all.append("".join(results_special_characters)) while True: test_num=[i for i in range(200,800)] if random.choice(test_num)>300 and random.choice(test_num)<600: results_all.append(random.choice(test_num)) break else: continue return results_all[0]+results_all[1]+results_all[2]+str(results_all[3]) elif (task>3 and task<4): self.p_2=self.p_2+1 while len(results_letters_big)<4: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<3: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) while len(results_special_characters)<4: results_special_characters.append(random.choice(teshu)) results_all.append("".join(results_special_characters)) while True: test_num=[i for i in range(500,1400)] if random.choice(test_num)>600 and random.choice(test_num)<1200: results_all.append(random.choice(test_num)) break else: continue return results_all[0]+results_all[2]+results_all[1]+str(results_all[3]) elif (task>4 and task<9): self.p_3=self.p_3+1 while len(results_letters_big)<3: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<4: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) while True: test_num=[i for i in range(1100,2600)] if random.choice(test_num)>1200 and random.choice(test_num)<2400: results_all.append(random.choice(test_num)) break else: continue return results_all[1]+results_all[0]+str(results_all[2]) elif (task>9 and task<12): self.p_4=self.p_4+1 while len(results_letters_big)<3: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<4: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) while True: test_num=[i for i in range(2300,5000)] if random.choice(test_num)>2400 and random.choice(test_num)<5000: results_all.append(random.choice(test_num)) break else: continue return str(results_all[2])+results_all[1]+results_all[0] elif (task>12 and task<15): self.p_5=self.p_5+1 while len(results_letters_big)<4: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<5: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) while True: test_num=[i for i in range(4900,10000)] if random.choice(test_num)>5000 and random.choice(test_num)<10000: results_all.append(random.choice(test_num)) break else: continue return str(results_all[2])+results_all[0]+results_all[1] else: self.p_6=self.p_6+1 while len(results_letters_big)<5: results_letters_big.append(random.choice(zimu_dx)) while len(results_letters_small)<4: results_letters_small.append(random.choice(zimu_xx)) results_all.append("".join(results_letters_big)) results_all.append("".join(results_letters_small)) return results_all[0]+results_all[1] except IndexError,e: pass def count_data(self): print "生成100組帳號密碼的機率比例:" print "========帳號類比率=======" print "方案1: %s%% 方案2: %s%% 方案3: %s%% 方案4: %s%%" % (self.u_1,self.u_2,self.u_3,self.u_4) print "========密碼類比率=======" print "方案1: %s%% 方案2: %s%% 方案3: %s%% 方案4: %s%% 方案5: %s%% 方案6: %s%%" % (self.p_1,self.p_2,self.p_3,self.p_4,self.p_5,self.p_6) if __name__=='__main__': t=create_data() for i in range(0,100): print "生成帳號: %s 密碼: %s" % (t.username(),t.passwd()) t.count_data()