Func Rnd
# VBScript Rnd Function
* * Complete VBScript Reference Manual](#)
* * *
The Rnd function returns a random number. The number is always less than 1 but greater than or equal to 0.
### Syntax
Rnd[(number)]
| Parameter | Description |
| :--- | :--- |
| number | Optional. A valid numeric expression. If number is: * 0 - Rnd will return the next random number in the sequence. * =0 - Rnd will return the most recently generated number. * Omitted - Rnd will return the next random number in the sequence. |
## Examples
## Example 1
Random number:
document.write(Rnd)
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:
0.7055475
[Try it yourself Β»](#)
## Example 2
To avoid getting the same number every time as in Example 1, use the Randomize statement:
Randomize
document.write(Rnd)
Output of the above example:
0.4758112
[Try it yourself Β»](#)
## Example 3
Here's how to generate a random integer within a given range:
Dim max,min
max=100
min=1
Randomize
document.write(Int((max-min+1)*Rnd+min))
Output of the above example:
71
[Try it yourself Β»](#)
* * Complete VBScript Reference Manual](#)
YouTip