I've got ten textboxes that I want to fill with random numbers when the user clicks "Fill" on a menu. So I put the boxes into a ArrayList called TextBoxes and wrote the next two procedures:
Private Function ProduceRandomNumber(ByVal Min As Integer, ByVal Max As Integer) As Integer
Dim Num As New Random()
Return Num.Next(Min, Max)
End Function
Private Sub FillToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillToolStripMenuItem.Click
Dim RandomEntry As Integer
For Each TBox As TextBox In Textboxes
RandomEntry = ProduceRandomNumber(0, 9999)
TBox.Text = CStr(RandomEntry)
Next
End Sub
This fills all the boxes fine, but the first few are all identical, the next few are a different value but all the same, sometimes there's a couple more identical. It varies.
Q. What the heck is going on around here?
Private Function ProduceRandomNumber(ByVal Min As Integer, ByVal Max As Integer) As Integer
Dim Num As New Random()
Return Num.Next(Min, Max)
End Function
Private Sub FillToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillToolStripMenuItem.Click
Dim RandomEntry As Integer
For Each TBox As TextBox In Textboxes
RandomEntry = ProduceRandomNumber(0, 9999)
TBox.Text = CStr(RandomEntry)
Next
End Sub
This fills all the boxes fine, but the first few are all identical, the next few are a different value but all the same, sometimes there's a couple more identical. It varies.
Q. What the heck is going on around here?