Pseudo-random number generation
Previously, when testing the trend graph of the touch screen, some data was generated by simulation. In order to be lazy, I planned to simulate random data through the program, but the result went into another pit-how to generate random data, because Siemens does not have the syntax function of advanced syntax, and finally online Query information and find two ways
The nanosecond of the system clock should be a pseudo-random number
By reading the system clock inside the PLC, and then saving the nanoseconds of the system time to the corresponding variable by pulse
test environment
for reference only
Hardware Configuration
Item | Description |
---|---|
CPU | 1515-2-PN |
Order number | 6ES7-515-2AM01-0AB0 |
IP address | 192.168.0.1 |
Software configuration
Botou V15
program
Attached drawing
- Read the data type of the out interface of the system clock to select DTL
- M0.5 is the system clock, the pulse frequency is 1s
- out1 is the random number generated
LGF library generates random functions
LGF library download
Link: download link .
LGF library call
After the download is complete, the adding steps are as follows:
Call the internal function block of the library and drag it to the edit box on the left
- RET_VAL is used as the return value of the FC function, which is different from the OUT interface
- The global library provides two kinds of random numbers, integer and floating point
- The function block provides a range input interface for random numbers, minValue and maxValue