Private Sub Command1_ Click( )
Dim a(0 To 4) As Integer, b(1 To 4) As Integer
Dim key As String, s As String, n As Integer, k As Integer, i As Integer, j As Integer, sum As Integer
key="ABCDEFGHJKIMNC)PQRSTUVWXYZabdefghijklmnopqrstuvwxyz0123456789! @# $ %&.*"
Randomize
n= Val(Text1.Text)
a(0)=0:a(1)=26 :a(2)=52 :a(3)=62:a(4)=70 '记录每种符号的结束位置
s= ""
For i=1 To 4
b(i) =0 'b数组记录某类符号是否使用
Next i
sum=4 '当前未使用字符类型,初始为4种
Do While Len(s)+sum< n
k= '随机选择一个密码序号
s=s+ Mid(key, k, 1)
i= 1
Do While
i=i+ 1
Loop
b(i)= 1
sum=4-b(1)-b(2)-b(3)-b(4)
Loop
'生成剩余未出现元素密码,保证4种符号均有出现
For i=1 To sum
j=Int(Rnd*4)十1
Do While ( )
j=j Mod 4+1
Loop
b(j)=1
k=Int(Rnd * (a(j)-a(j- 1)))+a(j-1)+1
s=s+Mid(key, k, 1)
Next i
Text2.Text=s
End Sub