我的生成器每次运行时都会生成相同系列的密码
dXEFj1im
e3OpkLxq
4wKWi4SF
yBX7zb17
7kE3FLFw
yNDNNeH6
RsCjLEtP
7Zdtn1Xt
.
.
.
etc
任何人都可以看到需要改变的东西,我玩过的我不知道修复它。 感谢
功能
Function Pwd(ByVal strTemp As String) As String
Dim i As Integer, iTemp As Integer, bOK As Boolean, iLength As Integer
'48-57 = 0 To 9, 65-90 = A To Z, 97-122 = a To z
'amend For other characters If required
For i = 1 To 8
Do
iTemp = Int((122 - 48 + 1) * Rnd + 48)
Select Case iTemp
Case 48 To 57, 65 To 90, 97 To 122: bOK = True
Case Else: bOK = False
End Select
Loop Until bOK = True
bOK = False
strTemp = strTemp & Chr(iTemp)
' Initialize the seed using Timer.
Randomize (Timer)
Next i
Pwd = strTemp
End Function
The Sub
Sub RanPassword()
Dim rng As range
Dim LastRow As Long
With Sheets("sheet1")
LastRow = .range("E" & .Rows.Count).End(xlUp).Row
End With
For Each rng In Sheets("Sheet1").range("B2:B" & LastRow)
rng.Value = Pwd(rng.Value)
Next
End Sub
答案 0 :(得分:3)
您没有为随机数生成器播种。必须在每次新的运行中播种,以产生随机结果。它默认为某个数字,该数字生成相同的密码系列。您必须通过调用Randomize
函数来播种它。 Randomize
接受一个论点,即种子。系统时间是一个好但不安全的种子。