RAND (random value)
The RAND instruction calculates random integer values from a defined range.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the Micro810, L20E, L50E, and L70E controllers.
RAND

Parameter | Parameter Type | Data Type | Description |
---|---|---|---|
EN | Input | BOOL | When set to true, the instruction is enabled.
|
base | Input | DINT | Defines the supported set of numbers. |
RAND | Output | DINT | Random value in set [0..base-1]. |
ENO | Output | BOOL | Enables output. Applies to ladder diagram programs. |
RAND examples
RAND function block diagram example

RAND ladder diagram example

RAND structured text example

(* ST Equivalence: *) selected := MUX4 ( RAND (4), 1, 4, 8, 16 ); (* random selection of 1 of 4 pre-defined values the value issued of RAND call is in set [0..3], so 'selected' issued from MUX4, will get 'randomly' the value 1 if 0 is issued from RAND, or 4 if 1 is issued from RAND, or 8 if 2 is issued from RAND, or 16 if 3 is issued from RAND, *)
Results

Provide Feedback