Random number generator for PLC5

Contr_Conn

Member
Join Date
Sep 2003
Location
Ohio
Posts
2,557
Hi guys

I am looking if some one has random number generator for PLC5 in the range 0..9999. Don't ask why ;)

I did one quickly based on PLC clock, but it is not really good.
 
maybe you would like trying the way below:
first,you can use the "ton" instruction to generate a data--T4:1.acc.
secondly, you can use the "sin" instruction to generate a data between -1 to 1--sin(t4:1.acc)
at last,you can use the "cpt" instruction.

;)
 
Thanks for the idea,
I did not think about using TON.
The only problem I see that TON gives you constantly growing number.
May be usibng 2 TONs with different presets and substract values.
Any other ideas?
 
This is an extremely good routine used to generate random numbers in a PLC for random timer routines. Often with swimming pool jobs the features are required to be timed in a random fashion. I devised a random number generator for this purpose that could be limited between certain values. For example, feature one to be random timed on and off between 10 minute on and 5 minutes off etc. My example was somewhat more simple and unsophisticated than this but worked effectively and did what I wanted it to do. It was the subject of another post here where many of our illustrious contributors determined it was impossible to generate random numbers in a PLC. I disagreed because I had done it.
This particular routine was coded by Sleepy Wombat, who obviously has too much time on his hands. Yes, it is a very impressive piece of code, and it does generate random numbers beautifully. It was developed in Omron CX-Programmer and was obviously coded for use in an Omron CJ1/CS1 PLCs. These PLCs have an awesome instruction set and are extremely powerfull. Very much my favourite PLCs at the moment. You can see from the code that the instruction set is, at the very least, extensive. I find it very difficult to go away from these beasts and have to work with a reduced instruction set in other brands. More people should become aware of these little dears and what they can do.
I might add that Sleepy Wombat is my supplier's representative for these lovely little things. He and I do collaborate quite a bit on coding, projects etc. We were both extremely frustrated over a job just recently where I was unable to read from a device using an Omron CJ1 serial port and CX-Protocol. I was trying to communicate from the CJ1 serial board to a generator controller through an Adam 4250 isolated RS232/485 converter. We are both very experienced with Omron, and other brands of, PLCs. We spent hours trying to resolve framing error issues and occassional information from the device. The device is manufactured here in Ozz and has a combined RS422/485 port that is designed to fit all variants of 422/483 Modbus RTU communications. RTU commons and all sorts of things. At the end of the day the problem turned out to be termination of the comms line, again. We had tried standard 120 ohm resistor, 120 ohm resistor and 22pf ceramic in series and parallel etc etc. Removing the resistor from the Adam 4520 solved the problem. Extremely frustrating and time consuming. It now works bl**** well.
I guess that anyone unfamiliar with Omron would have trouble interpreting *F (floating point multiply) FLTL (32 bit to floating) A351 (clock area) etc. *, /, + and - would probably be more familiar, particularly to those of us who use Windows calculator and Excel.
The instruction reference manual for these things is 1135 pages long. I think there are about 500 instructions available for use in the PLCs. Leaves you a lot of room to do a lot of fancy routines.
Congratulations to Sleepy for devising this little piece of very effective and simple code. As I said, too much time on his hands.
beerchug
 
Thanks Bob
This is exactly what I want.
I will convert it to A-B and try. I have only SLC here today, but will try it Monday with PLC5.
I did very similar, but used a different formula. Your formula looks better.

I need this to generate random security code for a kids project.
They must remeber it and use it next time.
They will get a new code every time they use it.
Just a toy.
 
Elevmike: Yes they do have a nice Casino in Sydney....
However, i wrote the code to apply random noise to a simulated analogue input signal to test PID routines in the PLC....

And to my mate BobB.......
This particular routine was coded by Sleepy Wombat, who obviously has too much time on his hands. Yes, it is a very impressive piece of code, and it does generate random numbers beautifully.
Too much time ??? Oh well...With all of this extra time i have thought of another use for the code...I think that i might apply it to your next invoice. Ie BobB's Standard cost + Random Number (this could be interesting.... :D :p ;) only kidding...
 
Random number generator

Program for ST:

wTemp := DINT_TO_WORD ( FREERUN ());
uShift := DINT_TO_UINT( ABS(FREERUN ()) MOD 16);
wRND := ROL_WORD (IN := wTemp, N := uShift);
rRND := UINT_TO_REAL(WORD_TO_UINT(wRND));
OUT := rRND *(MAX_OUT - MIN_OUT)/65535.0 + MIN_OUT;


Function FREERUN return time in microseconds.

Example for Concept 2.5 SR2 http://forum.mrplc.com/index.php?act=Downloads&CODE=02&id=296
 

Similar Topics

Hey folks, I was just wondering what thoughts were about a completely 100% random number generator. I looked on The Google but didn't really open...
Replies
54
Views
16,437
Hello, Could somebody please help me out with coding a 'Random number generator' in vijeo citect. For example if i create an analog Local...
Replies
3
Views
3,726
Hi,Does anybody know if there are any routines in unity pro that produce random numbers like the routine rand() in C ?
Replies
1
Views
4,023
Ive got a client that needs random numbers generated for a security system. Just want to know if any 1 has some ladder or ST software or scripts...
Replies
11
Views
8,810
Can anyone help me create a few ladder logic lines to randomly generate intergers btw 0-100. I have tryed loading the scan timer value, then ANDD...
Replies
16
Views
13,279
Back
Top Bottom