Hello, world !
I have a question about this code,
it's a code for generating a random string (of 10 digits)
so I can use it to create random passwords. I use this for all my passwords.
It works great, the code.
But I see somewhere in the code (on the 3rd line)Code:Public Class Form1 Private Function GenerateString(ByVal length As Integer, ByVal content As Integer, ByVal casing As Integer) As String Dim r, r1, r2 As New Random Dim gString As String = String.Empty Dim LowAlph As String = "abcdefghijklmnopqrstuvwxyz" Dim UppAlph As String = LowAlph.ToUpper Dim addLetter As Char Do Until gString.Length = length Select Case casing Case 0 Select Case r.Next(0, 2) Case 0 addLetter = LowAlph.Substring(r1.Next(0, 25), 1) Case 1 addLetter = UppAlph.Substring(r1.Next(0, 25), 1) End Select Case 1 addLetter = UppAlph.Substring(r1.Next(0, 25), 1) Case 2 addLetter = LowAlph.Substring(r1.Next(0, 25), 1) End Select Select Case content Case 0 Select Case r.Next(0, 2) Case 0 gString &= addLetter Case 1 gString &= r1.Next(0, 9) End Select Case 1 gString &= r1.Next(0, 9) Case 2 gString &= addLetter End Select Loop Return gString End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = GenerateString(TextBox2.Text, 0, 0) End Sub End Class
but r2 isn't used everwhere else in the code.Code:Dim r, r1, r2 As New Random
Is r2 not nessecary(sp) ? Can I discard it, end delete from code ?
I want to write (this)code as clean(short) as possible, so it uses minimum
memory/cpu!
I'm beginning to become a beginner, so please explain in simple.
why this code doesn't use the variable r2
is this code actually random ? that's what I wanna know.
And I thank you.
bye




VB.NET 2010 - Windows XP SP3
Reply With Quote