![]() |
||
|
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
| ||
New Here? Please read this important info!!!
|
|
#1 |
|
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.. |
|
|
|
#2 |
|
Lifetime Supporting Member
|
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. |
|
|
|
#3 |
|
Member
|
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 |
|
|
|
#4 |
|
Member
|
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 |
|
|
|
#5 |
|
Lifetime Supporting Member
|
Nice one!
I'll try it ASAP. Just for fun.
__________________
If it looks like a Cat... |
|
|
|
#6 |
|
Guest
Posts: n/a
|
thanks
I will try these suggestions and see how it turns out.
Thanks for the help. |
|
|
|
#7 |
|
Member
|
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! |
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |