vendredi 18 septembre 2015

Class Random not working as expected

This block is supposed to generate a random 8 character password. When tested, it displays the same 8 characters in the textbox. If I go line by line for the entire iteration, it works properly. If I go line by line for a few loops, then let it run the rest of the characters will be repeat. For example, I break for 3 lines and then resume: abcddddd is my output.

What is causing this to happen?

 Private Sub generateBTN_Click(sender As System.Object, e As System.EventArgs) Handles generateBTN.Click
        generateTXT.Clear()
        While generateTXT.Text.Length < 9
            Dim rn As Random = New Random
            Dim num As Integer = rn.Next(33, 126)
            While num = 40 Or num = 41 Or num = 59 Or num = 61
                num = rn.Next(33, 126)
            End While
            Dim numSTR As String = ChrW(num).ToString
            generateTXT.Text = generateTXT.Text & numSTR
        End While
    End Sub




Aucun commentaire:

Enregistrer un commentaire