VBScript Rnd function
Rnd function returns a random number. Number is always less than 1 but greater than or equal to 0.
grammar
Rnd[(number)]
参数 | 描述 |
---|---|
number | 可选。有效的数值表达式。 如果数字是:
|
Examples
Example 1
random number:
<script type="text/vbscript">
document.write(Rnd)
</script>
document.write(Rnd)
</script>
Please note that you will get the same number. To avoid this, use the Randomize statement in Example 2.
Examples of the above output:
0.7055475
try it"
Example 2
In order to avoid as in Example 1 to give the same numbers each time, use the Randomize statement:
<script type="text/vbscript">
Randomize
document.write(Rnd)
</script>
Randomize
document.write(Rnd)
</script>
Examples of the above output:
0.4758112
try it"
Example 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>
Dim max,min
max=100
min=1
Randomize
document.write(Int((max-min+1)*Rnd+min))
</script>
Examples of the above output:
71
try it"
Complete VBScript Reference