Random number generator for PLC5

It depends on the seed; the PLC-5 has six status words in its clock (year, month, ..., second); the low 5 to 6 bits of each of (day of month, hour of day, minute of hour, second of minute) would combine into a reasonable one-time, 20-bit+ seed that would generate one of a million different pieces of the sequence each time.
I understand that. The problem is that the seed only starts the sequence of pseudo random numbers at a different spot.




Also, if someone has chosen a PLC do so summat random, then it is unlikely to be important that the quality of the RNG is not at a crytographically-secure level; if it's important e.g. a casino, then they have enough money and don't have to fiddle around with underpowered toys.
Random number generators in a PLC and motion controllers are good for testing software.
 
I understand that. The problem is that the seed only starts the sequence of pseudo random numbers at a different spot.
Sigh.


I understand that, which is why I pointed out a way to choose a random location to start out of millions, out of the sequence that is two or four billion long. But that is a concern for cryptographers, not PLC programmers.



Random number generators in a PLC and motion controllers are good for testing software.

In that environment, it is only the distribution of random numbers that is important, and even the humble LCG will be more than adequate; for that matter, a fifteen- or sixteen-bit overall LCG (32-64k elements long), using the same seed and the same sequence every time will be fine most of the time (e.g. not simple simon).

The is no need to put lipstick on the pig.


At least the PLC-5 has trig (cosine and sine) and natural log functions; when I wrote a Gaussion RNG for MicroLogix 1100, I had to build those from scratch to implement the Box-Muller algorithm.
 
Google "Center Squared"


I think middle square was meant, also adding [von neumann] would help.


Love this bit from the wikipedia pages:


The method was invented by John von Neumann, and was described at a conference in 1949. [...]


In the 1949 talk, Von Neumann quipped that, "Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin."
 
Last edited:
I just put my suggested method in a SLC5/05 (mo PLC 5's laying around in my house)


Using 4 timers, 0.01 base, presets of 6, 4, 5, & 3, each triggering a counter PRE 50.


I used integer file N12 and put random numbers 0 - 9 from N12:0 to N12:51. I entered them blindly without looking at the keypad then checked for double digit numbers and changed them to only the first digit.


Using a 5th 0.01 timer with a PRE of 100 for 1 second I triggered my CPT instruction.
Logging the results in Excel through AdvancedHMI/EPPS I let it run for a few minutes. The resulting numbers show no obvious pattern, range from 104 to 9638, and had no duplicate numbers when I sorted the Excel data.
Going to let it run and see how many of the 65,000 rows I can fill then look through it when I get a couple days.
As far as any real need for a random number generator not using a dedicated supercomputer I think this should be good enough.
 
I just put my suggested method in a SLC5/05 (mo PLC 5's laying around in my house)


Using 4 timers, 0.01 base, presets of 6, 4, 5, & 3, each triggering a counter PRE 50.


I used integer file N12 and put random numbers 0 - 9 from N12:0 to N12:51. I entered them blindly without looking at the keypad then checked for double digit numbers and changed them to only the first digit.


Using a 5th 0.01 timer with a PRE of 100 for 1 second I triggered my CPT instruction.
Logging the results in Excel through AdvancedHMI/EPPS I let it run for a few minutes. The resulting numbers show no obvious pattern, range from 104 to 9638, and had no duplicate numbers when I sorted the Excel data.
Going to let it run and see how many of the 65,000 rows I can fill then look through it when I get a couple days.
As far as any real need for a random number generator not using a dedicated supercomputer I think this should be good enough.
That would be random enough for most purposes but doesn't any body want a real solution? The SLC5 has a BSL, BSR and XOR blocks.
 
That would be random enough for most purposes but doesn't any body want a real solution? The SLC5 has a BSL, BSR and XOR blocks.


With BSL and BSR shifting the bits only one position per instruction, requiring the extra step of dis-arming the BSL/R one-shot sixteen times as well? No thank you: just because something can be done doesn't mean it should be done in production; someone else is going to have to look at the code someday, or even the OP a few months hence. The other proposals here, or even LCG, are real enough; PLCs aren't used for cryptography, except perhaps by masochists.


Putting that algorithm into a PLC-5 would be like using a PLC PID for hydraulics control.
 
I suspect AND/DIV/AND would be quicker than sixteen BSR/disarm pairs; even it is close, the former would certainly be not quite so ugly.
Why 16 BSR? Can't one BSR or BSL shift 64 bits in one scan?
I thought this was the whole purpose of the BSL and BSR blocks, to keep track of things on a conveyor or similar. I could not see a limit to the number of bits that a BSR or BSL could shift.
Does a BSL take multiple scans to do shift bits in a bit file?
 
Why 16 BSR? Can't one BSR or BSL shift 64 bits in one scan?


No, because unlike C, which is all the power of assembler with all the convenience of assembler, PLCs are none of the power with all of the convenience.


I thought this was the whole purpose of the BSL and BSR blocks, to keep track of things on a conveyor or similar. I could not see a limit to the number of bits that a BSR or BSL could shift.



As I am sure you know, uninformed thinking is not very useful; this screen capture is from a PLC-5 Instruction Set Reference manual Cf. this link:


xxx.png


Can you see it now?



Does a BSL take multiple scans to do shift bits in a bit file?


No, it moves all bits by one bit position per one rising edge of its input rung, which rising edge is typically only available on every other scan at most, but there are techniques to get around that.






See also here cf. this link:

xxxx.png
 
Last edited:
No, it moves all bits by one bit position per one rising edge of its input rung, which rising edge is typically only available on every other scan at most, but there are techniques to get around that.
Moving all the bits one bit position per scan is that is required.
The every other scan part is a limitation but there are ways around that. Use 2 if a new random number is required every scan.
 
Moving all the bits one bit position per scan is [all?] that is required.


While that may be adequate in some cases, there is no way that is correct for every application.



The every other scan part is a limitation but there are ways around that.


As already noted.


Use 2 if a new random number is required every scan.


No, the number would be 16, not 2, and actually 32 with the Marsaglia algorithm.


Anyway, like I wrote several posts ago, AND/DIV/AND would be better.
 

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,512
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,750
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,030
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,853
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,320
Back
Top Bottom