I have run this code numerous times with different upper & lower bounds. I have deleted the randomize statement, included a single randomize statement. I have simplified the X1 = ... equations.
The end result has always been the same. The upperbound number appears more often than the lowerbound number by a factor of 20:1. The numbers in between are skewed as well. A graph of frequency of each number is triangular, 0 at the low end and max at the left end.
I have always accepted that random numbers created with the RND() or RAND() functions are not truly random but I would expect a better distribution.
Is there an error in my code or is there a more reliable way to create a random number?
Code:
Sub Randoms()
Dim x As Integer, x1 As Integer, x2 As Integer, x3 As Integer, x4 As Integer, x5 As Integer
For x = 1 To 500
'Random # = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Randomize
x1 = Int((Cells(200, 10) - Cells(200, 11) + 1) * Rnd + Cells(200, 11))
Randomize
x2 = Int((Cells(200, 10) - Cells(200, 11) + 1) * Rnd + Cells(200, 11))
Randomize
x3 = Int((Cells(200, 10) - Cells(200, 11) + 1) * Rnd + Cells(200, 11))
Randomize
x4 = Int((Cells(200, 10) - Cells(200, 11) + 1) * Rnd + Cells(200, 11))
Randomize
x5 = Int((Cells(200, 10) - Cells(200, 11) + 1) * Rnd + Cells(200, 11))
Cells(x, 1) = x1
Cells(x, 2) = x2
Cells(x, 3) = x3
Cells(x, 4) = x4
Cells(x, 5) = x5
Next
End Sub
The end result has always been the same. The upperbound number appears more often than the lowerbound number by a factor of 20:1. The numbers in between are skewed as well. A graph of frequency of each number is triangular, 0 at the low end and max at the left end.
I have always accepted that random numbers created with the RND() or RAND() functions are not truly random but I would expect a better distribution.
Is there an error in my code or is there a more reliable way to create a random number?