Random Numbers....

yerok72

Guest
Y
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..
 
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
 
Last edited:
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
 
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
 
thanks

I will try these suggestions and see how it turns out.
Thanks for the help.
 
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!
 

Similar Topics

Hi there, Has anyone ever had to generate random numbers for an application? I can do this with an algorithim using the RTC as a seed but what...
Replies
15
Views
10,703
Does anyone have any representative code they're willing to share that will will generate some random numbers? I'm playing around with...
Replies
4
Views
12,592
Hello Everybody, We have an DL340 cpu whcih inputs 4-20 ma signal from scales to show the weights. Now this value needs to be subtracted from a...
Replies
1
Views
1,683
G
I have a DL340 which takes the 4-20 ma signal from WI127( Scale) analoge bioard.when scale shows 0 Kg -PLC shows high random numbers when I...
Replies
3
Views
3,116
Looking for some advice for backing up the programs on a bunch of old random PLCs. All I'm really concerned about is getting the program out of...
Replies
43
Views
4,596
Back
Top Bottom