Rnd
Generates a decimal fraction number using the optional argument value (Num) to determine the sequence of the (random) number generation.
Rnd expects the argument (Num) if supplied, to be a valid numeric value.
If Num is less than zero, Rnd generates
the same number every time, using Num as
the seed. If Num is equal than zero, Rnd
repeats the most recently generated number. If Num is greater than zero, Rnd generates the next
random number in the sequence. If Num is
not supplied, Rnd generates the next random number in the
sequence.
Before calling Rnd, use the Randomize statement without an argument to initialise the random-number generator with a seed based on the system timer.
Note: The square brackets
[ ]in the syntax indicate that the argument is
optional.
Do NOT include the square brackets in your code.
Syntax
Rnd[(Num)]
Num:
An Integer or expression representing a valid numeric value.
Return Value
Returns a (random) decimal fraction number influenced by the (Num) provided in the argument. The return value lies in the range of less than 1 but greater than or equal to 0.
Related Functions
Example
Dim vntRndValue
Randomize ' Initialize random-number generator.
vntRndValue = Int((6 * Rnd) + 1) ' returns a value between 1 and 6