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.

New Here? Please read this important info!!!


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

Reply
 
Thread Tools Display Modes
Old July 26th, 2020, 01:34 AM   #31
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,184
Quote:
Originally Posted by drbitboy View Post
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.




Quote:

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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old July 26th, 2020, 08:13 AM   #32
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by Peter Nachtwey View Post
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.



Quote:
Originally Posted by Peter Nachtwey View Post
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.
  Reply With Quote
Old July 26th, 2020, 09:43 AM   #33
jdbrandt
Lifetime Supporting Member
United States

jdbrandt is offline
 
jdbrandt's Avatar
 
Join Date: Oct 2002
Location: Pennsylvania
Posts: 1,075
Google "Center Squared"
__________________
Jeffrey D.Brandt
  Reply With Quote
Old July 26th, 2020, 10:13 AM   #34
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by jdbrandt View Post
Google "Center Squared"

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


Love this bit from the wikipedia pages:


Quote:
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 by drbitboy; July 26th, 2020 at 10:15 AM.
  Reply With Quote
Old July 26th, 2020, 10:30 AM   #35
I_Automation
Member
United States

I_Automation is offline
 
I_Automation's Avatar
 
Join Date: Jun 2020
Location: Detroit, Michigan USA
Posts: 134
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.
  Reply With Quote
Old July 26th, 2020, 09:08 PM   #36
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,184
Quote:
Originally Posted by I_Automation View Post
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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old July 27th, 2020, 09:07 AM   #37
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by Peter Nachtwey View Post
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.
  Reply With Quote
Old July 27th, 2020, 09:57 AM   #38
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,184
Quote:
Originally Posted by drbitboy View Post
With BSL and BSR shifting the bits only one position per instruction
That is all that is needed. I didn't see a limit to the number of bits that could be shifted.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old July 27th, 2020, 10:33 AM   #39
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by Peter Nachtwey View Post
That is all that is needed. I didn't see a limit to the number of bits that could be shifted.

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.
  Reply With Quote
Old July 28th, 2020, 12:55 AM   #40
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,184
Quote:
Originally Posted by drbitboy View Post
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?
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old July 28th, 2020, 07:21 AM   #41
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by Peter Nachtwey View Post
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.


Quote:
Originally Posted by Peter Nachtwey View Post
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?



Quote:
Originally Posted by Peter Nachtwey View Post
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 by drbitboy; July 28th, 2020 at 07:34 AM.
  Reply With Quote
Old July 28th, 2020, 09:25 AM   #42
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 7,184
Quote:
Originally Posted by drbitboy View Post
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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old July 28th, 2020, 10:22 AM   #43
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 1,214
Quote:
Originally Posted by Peter Nachtwey View Post
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.



Quote:
Originally Posted by Peter Nachtwey View Post
The every other scan part is a limitation but there are ways around that.

As already noted.


Quote:
Originally Posted by Peter Nachtwey View Post
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.
  Reply With Quote
Old July 28th, 2020, 10:59 AM   #44
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,942
Is there a Random post generator
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old July 28th, 2020, 02:03 PM   #45
the_msp
Lifetime Supporting Member
United Kingdom

the_msp is offline
 
the_msp's Avatar
 
Join Date: May 2008
Location: Northern Ireland
Posts: 930
Quote:
Originally Posted by Firejo View Post
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
https://youtu.be/6avJHaC3C2U?t=943
__________________
Regards,

Patrick G. B.Eng MIET

Making the flashy lights flash since the 90's

SCADA - Inductive Automation Gold Integrator | PLC | Control Panels | Robotics | Training

Connect with Matrix Engineering
  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
S7 Random Number Generator RRobbins LIVE PLC Questions And Answers 14 July 8th, 2016 08:36 AM
Allen Bradley 1761-NET-ENI Jezz LIVE PLC Questions And Answers 11 August 17th, 2007 08:56 PM
S7-416-2 DP Fault - SFB20 sparky64 LIVE PLC Questions And Answers 8 July 30th, 2004 03:48 AM
Philosophical Illusion? Terry Woods LIVE PLC Questions And Answers 71 June 28th, 2004 08:41 AM
"Random" number generation ajbachhuber LIVE PLC Questions And Answers 9 September 10th, 2003 09:41 PM


All times are GMT -4. The time now is 08:22 PM.


.