FB_RandomGenerator - General Information
Type: |
Function block |
Available as of: |
V1.0.3.0 |
Inherits from: |
- |
Implements: |
- |
Versions: |
Current version |
Creation of a random number
Generates a random number that lies within an interval with defined limits upon each call-up of the GetLreal or GetDint methods. As the generation of the random numbers is effected in accordance with the linear congruence method, a start value i_diNstart is required which is set by means of the Init method. This can be any integer > 0 which is located within the value range of data type DINT. The Init method therefore has to be called up once before the GetLreal or GetDint methods can be called up.
The linear congruence method generates a sequence of numbers in accordance with the following regulations:
z(i+1) = (a * z(i)) MOD m
Here, a and m must be suitable integers. z(0) corresponds to the start value i_diNstart. Our random generator uses a = 16807 and m = 2^31 - 1 (Mersenne prime number). This generates a sequence of numbers having the period 2^31, that is, the values only repeat after more than 2 billion numbers generated. These are used as random numbers.
NOTE: POU is not addressable!
The POU must not be called up.
The function block can be used by calling it up over methods and properties.