What is the syntax to generate a random number?

<variable holding number> = (<max> - <min> + 1) * Rnd + <min>
'where max is the highest value the random number can be
'where min is the lowest value the random number can be
'cast to Int if a non-decimal random is desired
'examples

Dim myNumber As Integer
myNumber = Int ((20 - 10 + 1) * Rnd + 10)
'examples of values generated: 12, 10, 20, 23

Dim myNumber As Double
myNumber = (20 - 10 + 1) * Rnd + 10
'examples of values generated: 12.2, 10.2, 10, 20, 19.3, 12.2
Advertisements