FB_RandomGenerator - General Information

Overview

Type:

Function block

Available as of:

V1.0.3.0

Inherits from:

-

Implements:

-

Versions:

Current version

Task

Creation of a random number

Description

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.

Interface

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.

Methods

Name

Description

GetDint

Generates a random number of the DINT type.

GetLreal

Generates a random number of the LREAL type.

Init

Definition of the default conditions. Has to be called up once before calling up GetDint or GetLreal.