Section 8. Processing and Math Instructions
8-23
Value of number Number returned
< 0
The same number every time, as determined by number.
> 0
The next random number in the sequence.
= 0
The number most recently generated.
number omitted
The next random number in the sequence.
The same random-number sequence is generated each time the instruction is
encountered because each successive call to the
Rnd
function uses the previous
random number as a seed for the next number in the random-number sequence.
To have the program generate a different random-number sequence each time it is
run, use the Randomize statement without an argument to initialize the random-
number generator before
Rnd
is called.
To produce random integers in a given range, use this formula:
Int((upperbound - lowe 1) *
Rnd
+ lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the lowest
number in the range.
Rnd Function Example
The example uses the Rnd function to generate random integer values from 1 to 9.
Each time this program is run, Randomize generates a new random-number
sequence.
Dim Wild1, Wild2
'Declare variables.
Randomize
'Seed random number generator.
Wild1 = Int(9 *
Rnd
+ 1)
'Generate first random value.
Wild2 = Int(9 *
Rnd
+ 1)
'Generate second random value.
Sgn Function
Used to find the sign value of a number.
Syntax
Sgn(
number
)
Remarks
Returns an integer indicating the sign of a number.
The argument number can be any valid numeric expression. Its sign determines the
value returned by the Sgn function:
If X > 0, then Sgn(X) = 1.
If X = 0, then Sgn(X) = 0.
If X < 0, then Sgn(X) = -1.
Sgn Function Example
The example uses Sgn to determine the sign of a number.
Dim Msg, Number
'Declare variables.
Number = Volt(1)
'Get user input.
Select Case
Sgn(
Number
)
'Evaluate
Number.
Case
0
'Zero.
Msg = 0
Case
1
'Positive.
Msg = 1
Case
-1
'Negative.
Msg = -1
End Select
Содержание CR9000
Страница 6: ...CR9000 Table of Contents iv This is a blank page ...
Страница 22: ...CR9000 Overview OV 16 This is a blank page ...
Страница 26: ...Section 1 Installation 1 4 CR9000 FIGURE 1 1 3 CR9000 Battery Pack ...
Страница 72: ...Section 3 CR9000 Measurement Details 3 28 This is a blank page ...
Страница 88: ...Section 5 Program Declarations 5 6 This is a blank page ...
Страница 217: ...This is a blank page ...