VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong> <strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong><br />
Rnd<br />
Description Returns a random number less than 1 but greater than or equal to 0.<br />
Usage realVal = Rnd[(number)]<br />
Arguments number<br />
Optional. The number argument can be any valid numeric expression.<br />
Result A Real value.<br />
Return Values A random number less than 1 but greater than 0.<br />
If number is Rnd generates<br />
Less than zero The same number every time, using number as the seed<br />
Greater than zero The next random number in the sequence<br />
Equal to zero The most recently generated number<br />
Not supplied The next random number in the sequence<br />
Remarks The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number<br />
determines how Rnd generates a random number: For any given initial seed, the same number<br />
sequence is generated because each successive call to the Rnd function uses the previous<br />
number as a seed <strong>for</strong> the next number in the sequence. Be<strong>for</strong>e calling Rnd, use the Randomize<br />
statement without an argument to initialize the random-number generator with a seed based on<br />
the system timer.<br />
To repeat sequences of random numbers, call Rnd with a negative argument immediately be<strong>for</strong>e<br />
using Randomize with a numeric argument. Using Randomize with the same value <strong>for</strong> number<br />
does not repeat the previous sequence.<br />
To produce random integers in a given range, use this <strong>for</strong>mula:<br />
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)<br />
Here, upperbound is the highest number in the range, and lowerbound is the lowest number in<br />
the range.<br />
See also Randomize<br />
Example Const UpperBound = 10<br />
Const LowerBound = 1<br />
Dim counter<br />
For counter = 1 to 10 ‘ Produces 10 numbers between 1-20<br />
value = Int((UpperBound-LowerBound+1)*Rnd + LowerBound)<br />
MsgBox “Random Number is = “ & value<br />
Next<br />
154 <strong>InduSoft</strong>, Ltd.