Random number generator for PLC5

Technically there is no such thing as a true random number generator in a computer. There is always a pattern although sometimes the pattern is so long it appears that it is random. Having said that someone discovered using a Lavalamps as an analog input creates a true random number generator.
https://en.wikipedia.org/wiki/Lavarand
 
Technically there is no such thing as a true random number generator in a computer. There is always a pattern although sometimes the pattern is so long it appears that it is random. Having said that someone discovered using a Lavalamps as an analog input creates a true random number generator.
https://en.wikipedia.org/wiki/Lavarand
Be practical. Although any pattern will eventually be repeated there are some that won't happen in a life time or while the earth still exists.
A lava lamp with an analog output? Give me a break. The AtoD converter has only some many bits of output. I you count sequences of analog output then there is still a limitation as the analog values will not change instantly.
 
Be practical. Although any pattern will eventually be repeated there are some that won't happen in a life time or while the earth still exists.
A lava lamp with an analog output? Give me a break. The AtoD converter has only some many bits of output. I you count sequences of analog output then there is still a limitation as the analog values will not change instantly.

Peter I'm wondering what it's like to be a so superior to everyone else. Yet again you took what was one persons input into an interesting topic and turn it into a personal attack. I could care less what you think about my thoughts on any topic and I think you taking it to a personal level speaks volumes to the kind of person you are.
 
Peter I'm wondering what it's like to be a so superior to everyone else. Yet again you took what was one persons input into an interesting topic and turn it into a personal attack. I could care less what you think about my thoughts on any topic and I think you taking it to a personal level speaks volumes to the kind of person you are.


he he

he probably unknowingly made use of it today

https://blog.cloudflare.com/randomness-101-lavarand-in-production/
 
One counter per digit needed
RES counter if /DN
Each counter triggered by a different TON timer, each with own short .PRE

Use counter .ACC as pointer to integer file of digits 0-9 in various orders, set counter .PRE to last integer used

CPT
(N99:[C5:1.ACC] * 1000) + (N99:[C5:2.ACC] * 100) + (N99:[C5:3.ACC] * 10) + (N99:[C5:4.ACC])


- OR -

Do a masked move of Watchdog scan time or Time Base (S:3 or S:4) and use those digits as pointers to the N99 file.
 
Last edited:
Doesn't a PLC5 have a bit shift block where many bits can be shifted at once? ANDing with 65535 simply means separating a 32 bit value into two 16 bit ones and treating them like an unsigned number.

Yes, I was merely stating your linked C# example isn't a direct drop in. Probably better to reference PLC code, not C# code. But, that's just me.
 
Doesn't a PLC5 have a bit shift block where many bits can be shifted at once? ANDing with 65535 simply means separating a 32 bit value into two 16 bit ones and treating them like an unsigned number.


No, not like C/C++ has the >> operator.

The PLC-5 Bit Shift instructions (e.g. here) shift by one bit position at a time, so to get the equivalent of C/C++ [>>16], i.e. shift right by 16 in PLC-5, it may be easier to

  1. AND with -65536,
  2. DIVide by 65536,
  3. AND with 65535,
in that order.
 
Yes, I was merely stating your linked C# example isn't a direct drop in.
It is the algorithm that is important. Some assembly may be required.



Probably better to reference PLC code, not C# code. But, that's just me.
Do an internet search for "random number generator PLC5". All you get it this thread. There aren't any PLC5 random number generator examples.



I don't have a PLC5 and have only programmed one once in a galaxy far far away.


The key is the algorithm. There are a few good algorithms. Many were generated by George Marsaglia

https://en.wikipedia.org/wiki/George_Marsaglia

I use the algorithm I posted a link to. However, that may not have been the easiest to implement on a PLC5. I would consider the XorShift section of this


https://en.wikipedia.org/wiki/Linear-feedback_shift_register
Since I think it could be implemented with a BSL or BSR instruction and some XOR blocks.


Can you handle a BSL or BSR blocks and some XOR blocks?


Now can someone implement a 16 bit and 32 bit LFSR on a AB PLC?It should be easy for LD [] to do it on a S7.
The problem will be solved.


I can think of only one potential problem. The generated numbers will appear random but the sequence of numbers will always be the same. This may be good or bad depending on needs.


Some people of thin skin.
 
It is the algorithm that is important. Some assembly may be required.


Of course.


I can think of only one potential problem. The generated numbers will appear random but the sequence of numbers will always be the same. This may be good or bad depending on needs.


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.


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.
 

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,499
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,747
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,028
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,849
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,312
Back
Top Bottom