需求分析:
有兩種寫法:
1. 隨機生成三個數字,再隨機生成3個字母,兩個相加變成密碼
a = random.sample(string.digits,3)
b = random,sample(string,ascii_letters,3)
password = "".join(a+b)
2.隨機生成個六個數字和字母匯合的密碼
p = random.sample(string.digits+string,ascii_letters,6)
password = "".join(p)
importstring,random,os
f = open("
stus.txt
",encoding="
utf-8")
f2 = open("
stus_new.txt
","w
",encoding="
utf-8")
for line in
f: line =line.strip()
ifline:
#a = random.sample(string.digits,3)
#b = random.sample(string.ascii_letters,3)
#password = "".join(a+b)
p = random.sample(string.ascii_letters+string.digits,6)
password = ""
.join(p)
new_line = line+'
,'+password+"\n"
f2.write(new_line)
f.close()
f2.close()
os.remove(
"stus.txt")
os.rename(
"stus_new.txt
","stus.txt
")
隨機生成隨機數
現畫乙個command命令按鈕,進行貼上。private sub command1 click show me scale 0,0 18,8 me.auto redraw true me.draw mode 2 circle 3,4 3,vb red me.auto redraw false lin...
隨機數生成
原型 void srand unsigned seed 用法 srand和rand 配合使用產生偽隨機數序列。rand函式在產生隨機數前,需要系統提供的生成偽隨機數序列的種子,rand根據這個種子的值產生一系列隨機數。如果系統提供的種子沒有變化,每次呼叫rand函式生成的偽隨機數序列都是一樣的。sr...
生成隨機數
1 生成num位數驗證碼 用於簡訊驗證功能 public static random rand new random public static string getcode int num result,s k return result random r new random 建立乙個隨機數生成...