2

我的生成器每次运行时都会生成相同系列的密码

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

潜艇

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
4

1 回答 1

3

您没有播种随机数生成器。它必须在每次新运行时播种,以产生随机结果。它默认为某个数字,并且该数字会生成相同系列的密码。您必须通过调用该Randomize函数来播种它。Randomize接受一个论点,即种子。一个好的但不安全的种子是系统时间。

于 2013-06-18T16:47:15.220 回答