Method: Rnd for VBS
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: Rnd for VBS
Method: Rnd for VBS
Generates a random number.
vRnd = Object.Rnd(number)
| Object | VBS Object with this method. You do not need to specify this object. |
| number | Variant Specifies how the Rnd method generates the random number. If the value is smaller than or equal to 0, the Rnd method always generates the same random number. If you do not enter the value, or if the value is greater than 0, the Rnd method generates the next random number. |
| vRnd | Variant Receives the random number which is greater than or equal to 0 and less than 1. You should call the Randomize method before calling the Rnd method. If you do not call Randomize, the Rnd method always generates the same random number sequence when called. |
The following example generates random numbers in the range between LowerBound to UpperBound:
Function RndRange(LowerBound, UpperBound) Call Randomize ' Initialize random-number generator. RndRange = Int((UpperBound - LowerBound + 1) * Rnd + LowerBound) End Function