Chapter 6 Applied Instructions 
6-347 
API    Instruction code  Operand 
Function 
1517    RAND  P 
S
1
, S
2
, D 
Random number 
Device
X  Y  M  S  T  C  HC  D  L  SM  SR  E  PR  K  16#  “$”  DF 
16-bit instruction (7 steps) 
Symbol: 
S
1
:
Minimum value  Word   
S
2
:
Maximum value  Word   
D
:
Device in which the result is stored  Word   
Explanation:   
1.  The instruction is used to generate the random number within the range between the minimum 
value in S
1
 and the maximum value in S
2
, and the result is stored in D. 
2.  If the value in S
1
 is larger than the value in S
2
, the values in S
1
 and S
2
 are taken as the 
maximum value and the minimum value respectively when the instruction is executed.   
Example:   
When X0.0 is ON, the random number within the range between the minimum value in D0 and the 
maximum value in D10 is generated, and the result is stored in D20. 
 
Additional remark: 
The values in S
1
 and S
2
 should be within the range between 0 and 0~32767. If the value in S
1
 or S
2
 
exceeds the range, the instruction is not executed, SM0 is ON, and the error code in SR0 is 
16#2003.