Tuesday, August 31, 2010

Visual Basic Math Statement : Randomize

Purpose : The Randomize statement seeds the random number generator, allowing the generation of a new sequence of random numbers.

Syntax :
Randomize [ lngSeed ]

lngSeed : Seed number for a sequence of pseudo random numbers ( optional )

Function RndInt ( intLoNum as Integer , intHiNum as Integer ) as Integer
Static blnSeeded as Boolean
Dim intRange as Integer
if blnSeeded = False Then
Randomize
blnSeeded = True
Enf if
intRange = intHiNum - intLoNum + 1
RndInt = Int ( intRange * Rnd + intLoNum )
End Function

This example is a function that uses the Randomize statement and Rnd function to return an integer in the range specified by the integer parameters intLoNum and intHiNum.

No comments:

Post a Comment