Sgn function – Campbell Scientific CR9000X Measurement and Control System User Manual
Page 319

Section 8. Processing and Math Instructions
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 - lowerbound + 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, I
'Declare variables.
BeginProg
Scan(100,mSec,3,0)
Randomize(I)
'Seed random number generator.
Wild1 = Int(9 *
RND
+ 1)
'Generate first random value.
Wild2 = Int(9 *
RND
+ 1)
'Generate second random value.
I = I + 1
'Change Seed value
NextScan
EndProg
SGN Function
The SGN function is used to find the mathematical 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
8-33