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.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


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

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old May 20th, 2002, 04:31 AM   #1
yerok72
Guest
 
Posts: n/a
Random Numbers....

I have been trying to make a random number generator using
RSLogix 5 and 500 but can seem to get it completely random. I have tried using different timers together but it still comes up with a pattern. I would appreciate any help. Thanks..
  Reply With Quote
Old May 20th, 2002, 07:37 AM   #2
Pierre
Lifetime Supporting Member
Vatican City State

Pierre is offline
 
Pierre's Avatar
 
Join Date: Apr 2002
Location: Montreal
Posts: 1,663
Try using something which varies, not according to your ladder but somtething else ... like the RTC (real time clock).

You can parse and add all the single digit and then end-up with a number which will be the result of something which is variable.

IMHO you cannot get a true random number in a PLC but you can get soething looking very much so!

For example;

Use a long timer, 1000 seconds
Every scan, move the acc. value to a register
Add it to the RTC seconds value registers into a third register
Multiply this register with the minute value
Parse the digits,
Multiply them with an interrupted value, corresponding with the scan time...
And so on...
'till your getting a random looking value
__________________
If it looks like a Cat...

Last edited by Pierre; May 20th, 2002 at 07:45 AM.
  Reply With Quote
Old May 20th, 2002, 10:22 AM   #3
akreel
Member
United States

akreel is offline
 
akreel's Avatar
 
Join Date: Apr 2002
Location: Milwaukee, WI
Posts: 1,172
Computers are not known for being able to generate true random numbers in the first place.

I believe "random numbers" are generated by moving a pointer in a table of "random" digits. I think there is some specific irrational number that is used to generate that table. To make things appear even more random, you use a timer to move the pointer around. When you're ready to access the table of "random" values, the pointer could be anywhere.

PLCs don't have random number functions because there's not much need for them. Usually we like to know how our controllers are going to behave, especially when they're connected to a few thousand dollars worth of hardware.

AK
  Reply With Quote
Old May 20th, 2002, 02:47 PM   #4
jvdcande
Member
Belgium

jvdcande is offline
 
jvdcande's Avatar
 
Join Date: Apr 2002
Location: Menen
Posts: 1,948
A couple of years agoo, I had the same problem. I transferred the solution used in an old Sinclair Spectrum to a Siemens S5 PLC. Basically this formula for an 16-bit integer random number is as follows:

1. Take a seed (usually the last random number generated, the RTC gives a better result)
2. Increment the seed by 1
3. Multiply by 75
4. Subtract the high byte from the low byte
5. Decrement this result by 1, which gives the new random number.

Originally in the Spectrum the formula was ((Seed+1)*75) MOD 65537 -1.

I found that my result, which gives a pseudo-random sequence of 65536 numbers, worked quitte well. I hope it does so for you too!

Regards,

Jean Pierre Vandecandelaere
Instructor PLC - SCADA
  Reply With Quote
Old May 20th, 2002, 02:50 PM   #5
Pierre
Lifetime Supporting Member
Vatican City State

Pierre is offline
 
Pierre's Avatar
 
Join Date: Apr 2002
Location: Montreal
Posts: 1,663
Nice one!

I'll try it ASAP. Just for fun.
__________________
If it looks like a Cat...
  Reply With Quote
Old May 20th, 2002, 04:12 PM   #6
yerok72
Guest
 
Posts: n/a
thanks

I will try these suggestions and see how it turns out.
Thanks for the help.
  Reply With Quote
Old May 21st, 2002, 12:09 AM   #7
jvdcande
Member
Belgium

jvdcande is offline
 
jvdcande's Avatar
 
Join Date: Apr 2002
Location: Menen
Posts: 1,948
Sorry, but I made a mistake in the steps to calculate the random number. Step 4 should state:

4. Subtract the high WORD from the low WORD

Sorry, if I confused you guys!
  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
displaying Hex numbers in VersaPro Dave Powers LIVE PLC Questions And Answers 7 August 27th, 2004 01:39 PM
PID - Velocity control of a mass on a spring. Peter Nachtwey LIVE PLC Questions And Answers 19 July 22nd, 2004 10:28 AM
Random Numbers LIVE PLC Questions And Answers 3 June 23rd, 2004 08:16 AM
Random DC Input Fluctuation on Trend Chart Hester LIVE PLC Questions And Answers 2 June 12th, 2004 12:02 AM
Need ONS Random Counter NightCraver LIVE PLC Questions And Answers 7 April 10th, 2003 09:07 PM


All times are GMT -5. The time now is 06:56 AM.


.