Upon playing with the graphics/random class - I have discovered something odd.
Private Sub Me_Load(sender As Object, e As EventArgs) Handles Me.Load
For i = 0 To 5000
DrawColor(GimmiRectangle)
Next
End Sub
Private Sub DrawColor(ByVal rNew As Rectangle)
Try
Dim g As Graphics = Me.CreateGraphics
g.DrawRectangle(New Pen(Color.FromArgb(New Random().Next(255), New Random().Next(255), New Random().Next(255))), rNew)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Function GimmiRectangle() As Rectangle
Try
Dim rect As New Rectangle(New Random().Next(1000), New Random().Next(1000), New Random().Next(1000), New Random().Next(1000))
Return rect
Catch ex As Exception
MsgBox(ex.ToString)
Return New Rectangle(0, 0, 0, 0)
End Try
End Function
This code will generate random sized/location rectangles and draw them to the screen. (place on a blank form)
The Random class seems to be not so random. For the most part - the rectangles appear to grow to the bottom right of the screen (with fairly few rendering in the margins.)
Has anyone else noticed this odd behavior with Random?