Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

VBScript Rnd function


May 13, 2021 VBScript


Table of contents


VBScript Rnd function


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.

Grammar

Rnd[(number)]

parameter describe
number Optional.Effective numerical expression.

If the number is:

  • <0 - RND will return the same number each time.
  • > 0 - RND will return the next random number in the sequence.
  • = 0 - RND returns the number of recently generated.
  • Omitting - RND will return the next random number in the sequence.

Instance 1

Random number:

<script type="text/vbscript">

document.write(Rnd)

</script>

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

The above example output results:

0.7055475

Try it out . . .

Instance 2

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

<script type="text/vbscript">

Randomize
document.write(Rnd)

</script>

The above example output results:

0.4758112

Try it out . . .

Instance 3

Here's how to produce random integers in a given range:

<script type="text/vbscript">

Dim max,min
max=100
min=1
Randomize
document.write(Int((max-min+1)*Rnd+min))

</script>

The above example output results:

71

Try it out . . .

VBScript Rnd function Complete VBScript reference manual