I'm having trouble with function that generates random numbers.
I have class dice:
Public Class dice
Private isHold As Boolean = False
Private rnd As Random
Private rolledDots As Integer
Public Sub roll()
If isHold = False Then
rnd = New Random
rolledDots = rnd.Next(1, 7)
End If
End Sub
End Class
I'm rolling dices through rollcup class:
Public Class rollCup
Public dices As New List(Of dice)
Sub New()
For i = 0 To 5
dices.Add(New dice)
Next
End Sub
Public Sub rollDices()
For Each dice In dices
dice.roll()
Next
End Sub
End Class
Problem is dices arent generating random numbers. Every dice has generated same number. I can only achieve random numbers by sleep threading in loop:
Public Sub roll()
If isHold = False Then
rnd = New Random
System.Threading.Thread.Sleep(50)
rolledDots = rnd.Next(1, 7)
End If
End Sub
or by showing each number in message box:
Public Sub roll()
If isHold = False Then
rnd = New Random
rolledDots = rnd.Next(1, 7)
MessageBox.Show(rolledDots)
End If
End Sub
Is there any other answer to my problem ? ps. sorry for bad english.