FB_RandomGenerator - General Information
Type: |
Function block |
Available as of: |
V1.0.0.0 |
The function block FB_RandomGenerator generates a pseudo-random number, herein referred to as a random number.
The function block FB_RandomGenerator generates a random number that is within an interval with defined limits upon each call of the GetLreal or GetDint methods.
The random numbers are generated according to the linear congruence method. The required start value i_diNstart is set using the Init method. This can be any integer > 0 which is located within the value range of data type DINT. The Init method has to be called once before the GetLreal or GetDint methods can be called.
The linear congruence method generates a sequence of numbers in accordance with the following regulations:
z(i+1) = (a * z(i)) MOD m
The variables a and m must be suitable integers. z(0) corresponds to the start value i_diNstart. The random generator uses the values 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 may practically be used as random numbers in many computations for specific purposes.
The function block does not provide any input or output parameters. An instance of the function block must not be called in your application program. To control and monitor, the function block provides methods.