VBScript Rnd
Function
The Rnd function returns a random number. The number is always less than 1 but greater than or equal to 0.
Syntax
Parameter | Description |
---|---|
number | Optional. A valid numeric expression. If the number is: <0 - Rnd will always return the same number.<br> >0 - Rnd will return the next random number in the sequence.<br> =0 - Rnd will return the most recently generated number.<br> Omitted - Rnd will return the next random number in the sequence. |
Example
Example 1
Random number:
Note that you will get the same number each time. To avoid this, use the Randomize statement as shown in Example 2.
Output of the above example:
Example 2
To avoid getting the same number each time as in Example 1, use the Randomize statement:
Output of the above example:
Example 3
Here's how to generate a random integer within a given range:
Output of the above example: