Hello, was trying to create random password generator.
First time when it runs it generates password, but next time also it generates same set of password. Seems there is some problem with the random no generation part. It always generates the same sequence
pls help
Anil
Private Const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Private Sub Form_Load()
Passwordgenerator
End Sub
Function Passwordgenerator()
Dim Passwordarray(7)
For i = 1 To 7
Passwordarray(i) = ""
Next
For i = 0 To 3
Label1(i).Caption = ""
Next
i = 1
'put this in a command button
'Add a label and name it label1,change its caption to "", set auto size to true
On Error Resume Next
For i = 0 To 4
b = 0
Do
DoEvents
b = b + 1
Debug.Print Int(Rnd * 26) + 1
a = Int(52 * Rnd)
ltr = Mid(LETTERS, a, 1) ' does the actual random generation
ltr2 = Asc(ltr) 'Numbervalue of the random Char
Select Case b
Case 2
Randomnumber = Int(Rnd * 10)
If Randomnumber <= 2 Then
Passwordarray(b) = Trim(Chr(64))
ElseIf Randomnumber >= 3 And Randomnumber <= 5 Then
Passwordarray(b) = Trim(Chr(37))
ElseIf Randomnumber >= 6 And Randomnumber <= 8 Then
Passwordarray(b) = Trim(Chr(36))
Else
Passwordarray(b) = Trim(Chr(95))
End If
Case 5
Passwordarray(b) = Trim(Str(ltr2))
Case 7
Passwordarray(b) = Trim(Str(ltr2))
Case Else
Passwordarray(b) = Chr(ltr2)
End Select
' Label1.Caption = Label1.Caption + Chr(ltr2) ' character value shown
Loop Until b = 8 ' The number of characters
Label1(i).Caption = Passwordarray(1) + Passwordarray(2) + Passwordarray(3) + Passwordarray(4) + Passwordarray(5) + Passwordarray(6)
Next
'Label1(1).Caption = Passwordarray(1)
'Label1(2).Caption = Passwordarray(1)
'Label1(3).Caption = Passwordarray(1)
End Function
First time when it runs it generates password, but next time also it generates same set of password. Seems there is some problem with the random no generation part. It always generates the same sequence
pls help
Anil
Private Const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Private Sub Form_Load()
Passwordgenerator
End Sub
Function Passwordgenerator()
Dim Passwordarray(7)
For i = 1 To 7
Passwordarray(i) = ""
Next
For i = 0 To 3
Label1(i).Caption = ""
Next
i = 1
'put this in a command button
'Add a label and name it label1,change its caption to "", set auto size to true
On Error Resume Next
For i = 0 To 4
b = 0
Do
DoEvents
b = b + 1
Debug.Print Int(Rnd * 26) + 1
a = Int(52 * Rnd)
ltr = Mid(LETTERS, a, 1) ' does the actual random generation
ltr2 = Asc(ltr) 'Numbervalue of the random Char
Select Case b
Case 2
Randomnumber = Int(Rnd * 10)
If Randomnumber <= 2 Then
Passwordarray(b) = Trim(Chr(64))
ElseIf Randomnumber >= 3 And Randomnumber <= 5 Then
Passwordarray(b) = Trim(Chr(37))
ElseIf Randomnumber >= 6 And Randomnumber <= 8 Then
Passwordarray(b) = Trim(Chr(36))
Else
Passwordarray(b) = Trim(Chr(95))
End If
Case 5
Passwordarray(b) = Trim(Str(ltr2))
Case 7
Passwordarray(b) = Trim(Str(ltr2))
Case Else
Passwordarray(b) = Chr(ltr2)
End Select
' Label1.Caption = Label1.Caption + Chr(ltr2) ' character value shown
Loop Until b = 8 ' The number of characters
Label1(i).Caption = Passwordarray(1) + Passwordarray(2) + Passwordarray(3) + Passwordarray(4) + Passwordarray(5) + Passwordarray(6)
Next
'Label1(1).Caption = Passwordarray(1)
'Label1(2).Caption = Passwordarray(1)
'Label1(3).Caption = Passwordarray(1)
End Function