Two cents
Code:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim stpw As New Stopwatch Dim passGen As New RandPassGen stpw.Reset() stpw.Start() For x As Integer = 1 To 10000000 'generate 10,000,000 passwords Dim s As String = passGen.NewPass 'Debug.WriteLine(s) Next stpw.Stop() Label1.Text = stpw.ElapsedMilliseconds.ToString("n0") End Sub Class RandPassGen Private Shared ReadOnly _PRNG As New Random 'define the characters to be used in the password Private Shared ReadOnly _UseChars As New System.Text.StringBuilder("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890") Private Shared ReadOnly _MinChars As Integer = 10 'minimum password size Private Shared ReadOnly _MaxChars As Integer = 10 'maximum password size Private _pass As New System.Text.StringBuilder Public Function NewPass() As String Dim sz As Integer = _PRNG.Next(_MinChars, _MaxChars) Me._pass.Length = 0 'new password For idx As Integer = 1 To sz 'generate the proper amount of characters Me._pass.Append(_UseChars(_PRNG.Next(0, _UseChars.Length))) 'randomly selected from characters to use Next Return Me._pass.ToString End Function End Class End Class




Reply With Quote