Chapter 8 Logic Instructions 
8-109 
 
FC 
RAND is used to generate a random number.   
 
 
  Parameters 
Meaning 
Description  Valid range   
In  Reserved  Input  Reserved 
Depends on the data type of 
the variable that the input 
parameter is connected to. 
Out 
Random 
number 
Output  Random number 
Depends on the data type of 
the variable that the output 
parameter is connected to. 
 
 
Boolean 
Bit string  Integer 
Real 
number 
Time, date 
String 
BOOL 
BYTE 
WORD 
DWORD 
LWORD 
USINT 
UINT 
UDINT 
ULINT 
SINT 
INT 
DINT 
LINT 
REAL 
LREAL 
TIME 
DATE 
TOD 
DT 
STRING 
In1 
             
● 
                       
Out                       
● 
     
Note:   
The symbol  ●  indicates that the parameter is allowed to connect to the variable or constant of the data 
type. 
  Function Explanation 
  RAND is used to generate a random number and the result is output to Out, within the range 
0~32767.   
  The input value does not have any effect on the random number to generate. But the value must 
be input for In. 
  To get the random number within a specific range, users just need perform the MOD calculation 
over the generated value and get the remainder. For example, the random number between 0 
and10 can be generated by writing the program RAND(0) MOD10. 
  Precautions for Correct Use 
  The input variable is not allowed to omit. An error will occur during the compiling of the software if 
the input variable is omitted. But the output variable is allowed to omit.