You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old February 20th, 2004, 07:16 PM   #1
Contr_Conn
Member
United States

Contr_Conn is offline
 
Contr_Conn's Avatar
 
Join Date: Sep 2003
Location: Ohio
Posts: 2,176
Random number generator for PLC5

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.
  Reply With Quote
Old February 20th, 2004, 08:35 PM   #2
elevmike
Member
United States

elevmike is offline
 
elevmike's Avatar
 
Join Date: Feb 2004
Location: Detroit, MI
Posts: 4,012
Why?

I just had to ask...
  Reply With Quote
Old February 20th, 2004, 09:16 PM   #3
konney
Member
China

konney is offline
 
Join Date: Feb 2004
Location: Xi'an
Posts: 22
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.

__________________
konney
  Reply With Quote
Old February 20th, 2004, 09:31 PM   #4
Contr_Conn
Member
United States

Contr_Conn is offline
 
Contr_Conn's Avatar
 
Join Date: Sep 2003
Location: Ohio
Posts: 2,176
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?
  Reply With Quote
Old February 20th, 2004, 10:52 PM   #5
BobB
Lifetime Supporting Member
Australia

BobB is offline
 
BobB's Avatar
 
Join Date: Jun 2002
Location: Sydney
Posts: 4,397
Talking

Here you go
Random Number Generator
beerchug
  Reply With Quote
Old February 20th, 2004, 11:15 PM   #6
elevmike
Member
United States

elevmike is offline
 
elevmike's Avatar
 
Join Date: Feb 2004
Location: Detroit, MI
Posts: 4,012
Bob,

Do they have casinos in Sydney? I cant imagine what else this could be used for...But I'm very impressed!
  Reply With Quote
Old February 21st, 2004, 06:26 AM   #7
BobB
Lifetime Supporting Member
Australia

BobB is offline
 
BobB's Avatar
 
Join Date: Jun 2002
Location: Sydney
Posts: 4,397
Talking

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
  Reply With Quote
Old February 21st, 2004, 10:16 AM   #8
Contr_Conn
Member
United States

Contr_Conn is offline
 
Contr_Conn's Avatar
 
Join Date: Sep 2003
Location: Ohio
Posts: 2,176
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.
  Reply With Quote
Old February 21st, 2004, 10:32 AM   #9
hesham
Member
Egypt

hesham is offline
 
hesham's Avatar
 
Join Date: Jan 2003
Location: cairo
Posts: 328
random

Contr_Conn
Check also This thread it could help you
thx
__________________
Hesham Farid
Egypt
------------------------------------------------------------------------
Let your plans be dark and impenetrable as night, and when you move, fall like a thunderbolt(Sun Tzu) .
  Reply With Quote
Old February 22nd, 2004, 02:15 AM   #10
Vetteboy
Member
Canada

Vetteboy is offline
 
Vetteboy's Avatar
 
Join Date: Jul 2002
Posts: 380
How about a scan counter that resets at 10,000.
Should be random enough for most uses
  Reply With Quote
Old February 22nd, 2004, 06:53 PM   #11
Sleepy Wombat
Member
Australia

Sleepy Wombat is offline
 
Sleepy Wombat's Avatar
 
Join Date: Oct 2003
Posts: 140
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.......
Quote:
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.... only kidding...
  Reply With Quote
Old September 8th, 2004, 02:57 AM   #12
leon78
Member
Russian Federation

leon78 is offline
 
Join Date: Jul 2004
Posts: 49
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...CODE=02&id=296
  Reply With Quote
Old December 27th, 2019, 08:07 AM   #13
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,236
> particularly to those of us who use Windows calculator and Excel.

heh. dry, very dry.
  Reply With Quote
Old July 22nd, 2020, 11:30 AM   #14
arnoldo
Member
Algeria

arnoldo is offline
 
Join Date: May 2020
Location: Australia
Posts: 3
I just had to ask...
  Reply With Quote
Old July 22nd, 2020, 12:51 PM   #15
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,185
This is what I use.
https://www.codeproject.com/Articles...ber-Generation
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
S7 Random Number Generator RRobbins LIVE PLC Questions And Answers 14 July 8th, 2016 08:36 AM
Allen Bradley 1761-NET-ENI Jezz LIVE PLC Questions And Answers 11 August 17th, 2007 08:56 PM
S7-416-2 DP Fault - SFB20 sparky64 LIVE PLC Questions And Answers 8 July 30th, 2004 03:48 AM
Philosophical Illusion? Terry Woods LIVE PLC Questions And Answers 71 June 28th, 2004 08:41 AM
"Random" number generation ajbachhuber LIVE PLC Questions And Answers 9 September 10th, 2003 09:41 PM


All times are GMT -4. The time now is 08:00 PM.


.