B
Barry
I am looking for opinions on using random number
generation in vb.net, I am using randomize and then using
the rnd function, I have done a test and it seems to be
pretty much random, what I'd like to know if anybody does
know is if it is truly random.
The code i am using is
Private Sub btnRandom_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnRandom.Click
Dim MyValue As Integer
Dim iCount(6) As Long
Dim i As Integer
Dim iMinimum As Integer
Dim iMaximum As Integer
Dim iLowestVal As Long
Dim iHighestval As Long
For i = 1 To 1000000
Randomize()
MyValue = CInt(Int((6 * Rnd()) + 1))
iCount(MyValue) += 1
Next i
iMinimum = 1
iMaximum = 1
iLowestVal = iCount(1)
For i = 1 To 6
If iCount(i) > iCount(iMaximum) Then
iHighestval = iCount(i)
iMaximum = i
End If
If iCount(i) < iCount(iMinimum) Then
iMinimum = i
iLowestVal = iCount(i)
End If
Next
MessageBox.Show("The lowest value is for " & iMinimum
& " equaling " & _
iLowestVal & vbCrLf & _
"The highest value is for " & iMaximum & " equaling "
& _
iHighestval)
End Sub
generation in vb.net, I am using randomize and then using
the rnd function, I have done a test and it seems to be
pretty much random, what I'd like to know if anybody does
know is if it is truly random.
The code i am using is
Private Sub btnRandom_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnRandom.Click
Dim MyValue As Integer
Dim iCount(6) As Long
Dim i As Integer
Dim iMinimum As Integer
Dim iMaximum As Integer
Dim iLowestVal As Long
Dim iHighestval As Long
For i = 1 To 1000000
Randomize()
MyValue = CInt(Int((6 * Rnd()) + 1))
iCount(MyValue) += 1
Next i
iMinimum = 1
iMaximum = 1
iLowestVal = iCount(1)
For i = 1 To 6
If iCount(i) > iCount(iMaximum) Then
iHighestval = iCount(i)
iMaximum = i
End If
If iCount(i) < iCount(iMinimum) Then
iMinimum = i
iLowestVal = iCount(i)
End If
Next
MessageBox.Show("The lowest value is for " & iMinimum
& " equaling " & _
iLowestVal & vbCrLf & _
"The highest value is for " & iMaximum & " equaling "
& _
iHighestval)
End Sub