how do i generate random number in vb ?
Printable View
how do i generate random number in vb ?
first in the forms load event write:
"randomize"
then when you wish to call a random number write:
"variablex = rnd()* 100" '<----will give you a random number 1 - 100
hope it helps
rob
here's a handy little piece of code:
VB Code:
Public Function RandomNumber(Min as Double, Max as Double, Optional WholeNumber as Boolean = True) If WholeNumber = True then RandomNumber = Int(Rnd() * (Max - Min) + Min) Else RandomNumber = Rnd() * (Max - Min) + Min End If End Function
job done, but da last code is more helpful !