[RESOLVED] loops for less times
Hey,
The code below only loops for 3 times. I am assuming it should loop for six times right? Can someone tell me why please?
Code:
Private Sub RandomGenerator1()
Dim AscChr As String, ChrAsc As String
Dim counter As Integer = 0
txtRandom1.Text = ""
For counter = 0 To 5
Randomize()
AscChr = Abs(Int(64 - 122) * Rnd() - 64)
ChrAsc = Chr(AscChr)
txtRandom1.Text += String.Format(ChrAsc)
counter += 1
Next
End Sub
Re: [RESOLVED] loops for less times
You're trying to create a random, 6-character string, correct?
vb.net Code:
Dim rng As New Random
Dim min As Integer = Convert.ToInt32("A"c)
Dim max As Integer = Convert.ToInt32("z"c) + 1
Dim chars(5) As Char
For index As Integer = 0 To chars.GetUpperBound(0)
chars(index) = Convert.ToChar(rng.Next(min, max))
Next
MessageBox.Show(New String(chars))
Always use the Random class to generate random numbers, never Randomize() and Rnd().
Re: [RESOLVED] loops for less times
Ok ,
Thanks for the advice. Can you pls tell me in why