Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generate same password in the same second
Message
From
11/11/2008 11:29:55
 
 
To
11/11/2008 11:17:42
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01360833
Message ID:
01361108
Views:
16
Yesterday: 'Dim loRnd As Random = New Random' was a problem which I can understand

but this: 'Static loRnd As Random = New Random' - I cannot understand since it is created only once and calling .Next() should return a different number whether (re)called immediately, within an hour or within a week


ps: loConsonants() , loDoubleConsonants() and loVowels() are all candidates for Static
_
>If I only have this, it generates the same value when being called in sequence:
>
>
>        ' Generate a password with alpha characters
>        ' expN1 Length of the password
>        Public Function GeneratePasswordAlpha(ByVal tnLength As Integer) As String
>            Dim lcPassword As String = ""
>            Dim llWroteConsonant As Boolean = False
>            Dim lnCounter As Integer = 0
>            Dim loConsonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"}
>            Dim loDoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"}
>            Dim loPasswordBuffer As New System.Text.StringBuilder
>            Dim loVowels() As Char = New Char() {"a", "e", "i", "o", "u"}
>            Statis loRnd As Random = New Random
>
>            For lnCounter = 0 To tnLength
>                If loPasswordBuffer.Length > 0 And Not llWroteConsonant And loRnd.Next(100) < 10 Then
>                    loPasswordBuffer.Append(loDoubleConsonants(loRnd.Next(loDoubleConsonants.Length)), 2)
>                    lnCounter = lnCounter + 1
>                    llWroteConsonant = True
>                Else
>                    If Not llWroteConsonant And loRnd.Next(100) < 90 Then
>                        loPasswordBuffer.Append(loConsonants(loRnd.Next(loConsonants.Length)))
>                        llWroteConsonant = True
>                    Else
>                        loPasswordBuffer.Append(loVowels(loRnd.Next(loVowels.Length)))
>                        llWroteConsonant = False
>                    End If
>                End If
>            Next
>
>            ' Size the buffer  
>            loPasswordBuffer.Length = tnLength
>
>            Return loPasswordBuffer.ToString
>        End Function
>
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform