Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript Rnd Function

VBScript Rnd Function


VBScript reference manual 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)]

Parameters Description
number Optional. A valid numeric expression.

If the number is:

  • <0 - Rnd returns the same number every time.
  • >0 - Rnd returns the next random number in the sequence.
  • =0 - Rnd returns the most recently generated number.
  • Omitted - Rnd returns the next random number in the sequence.
  • |

    Example

    Example 1

    Random numbers:

    Note that you get the same number every time. To avoid this, use the Randomize statement as in Example 2.

    The example above produces the following output:

    0.7055475

    Try it »

    Example 2

    To avoid getting the same number every time as in Example 1, use the Randomize statement:

    The example above produces the following output:

    0.4758112

    Try it »

    Example 3

    Here is how to generate a random integer within a given range:

    The example above produces the following output:

    71

    Try it »


    VBScript reference manual Complete VBScript Reference Manual