rand
Function Block A function block groups an algorithm and a set of private data. It has inputs and outputs. - Returns a pseudo-random integer value between 0 (zero) and (base - 1).
Inputs
Input |
Data Type |
Range |
Unit |
Default |
Description |
---|---|---|---|---|---|
base |
DINT |
1 to 2147483647 |
N/A |
No default |
The number of possible outcomes. Example: When base is 5, there are 5 possible outcomes: 0,1,2,3,4. |
Outputs
Output |
Data Type |
Range |
Unit |
Description |
---|---|---|---|---|
Return Value |
DINT |
0 (zero) to (base - 1) |
N/A |
The generated pseudo-random number. |
Remarks
- rand uses a low-quality, but fast number generation algorithm.
- It is sufficient for small bases and where security is not a concern.
- There is no way to seed the random number generator.
- It is possible to receive the same pattern of generated numbers after the controller reboots.
FBD Language Example
Not available.
FFLD Language Example
Not available.
IL Language Example
Not available.
ST Language Example
dieValue := 1 + rand(6);