Random Number Generator in PM573.
Hello,
I am trying to simulat one project and try to generate rendom value between range.
Please suggest me any function/Function block/formula.
Voted best answer
Hi
AFAIK the random number is not a function available in Codesys...
Answers
I'm not sure if this helps, but library functions sometimes use a simple linear congruential generator for pseudo random numbers:
y" = (ay' + c) mod m
Check the Internet for details.
If you're trying to simulate a varying signal, then then an evenly spaced random number doesnt really work very well - you're better to use a gaussian RNG because this gives you a random number where the next number in the sequence is "sort of" similar to the previous one. This way you get a value that wanders randomly up and down.
However, RNG's arent really required to simulate anything usefull. You can get usefull results by just adding a +/- 0.5% of range sine wave to to the simulated signal value.
If you just want something simple and dont care that its predicatable ....
i = 7 * i `mod` 11
--- you can seed "i" with any value but the ms of current time works well.
https://cdsmith.wordpress.com/2011/10...
once you have a simple RNG you can make a gaussian RNG ( if you really want to go to the trouble)
http://www.design.caltech.edu/erik/Mi...
Hi, maybe you should try the OSCAT Basic library, there are some functions available to calculate pseudo-random numbers (RDM, RDM2, RDMDW).
Library: http://www.oscat.de/component/jdownloads/summary/2-oscat-basic/3-oscat-basic-33
3.html
Documentation: http://www.oscat.de/component/jdownloads/summary/2-oscat-basic/9-oscat-basic333
-en.html
Good luck!
Add new comment