OT: Random Number Generator

saultgeorge

Lifetime Supporting Member
Join Date
Jul 2015
Location
Detroit
Posts
535
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 any of the results. Nothing looked all that definitive.
I'm asking because I lived in Vegas from 1999 to 2010 and I remember someone had invented one. I believe it was used to do something for gaming machines, and the inventor was able to beat the system and defeat it. (Of course).
Question is, is there REALLY a true RNG? Could one make one with a computer or PLC? My thought is probably so, however one would do well to limit the size of the number. Like a DINT is quite a large number from the negative end to the positive end. Anyway, thanks for reading and have a great week!!
 
There are no true software generated random number generators. Eventually they will repeat in theory but the stars may burn out before that happens.
Look at Mersenne Twister.
https://en.wikipedia.org/wiki/Mersenne_Twister
You can see it is used by many software packages and language libraries.

Hi, Peter thanks for the reply. I'll look at that link. I heard someone say one time that a power of 10^16 was defined as impossible; I.E. if it would take more than 10^16 "tries" for something to happen then it was considered an impossiblity. Maybe because as you stated the length of time involved. Even if it was say a 4 or 5 second process per attempt, that would be a long time. I'll have to calc that out. I hope you're enjoying retirement!
 
In a technical sense a computer cannot truly randomly generate a number, period. This is because computers do only what we tell them to do, and so the generation of the number is not 'random', but 'following set algorithm based on provided input/settings'.

For most purposes, however, true randomness is not necessary, merely unpredictability, which is produced fairly well by high-quality pseudo-random number generators.

To achieve true randomness (or something functionally identical), we can provide random inputs to the process, so that even though the process of generation is not random, the output is. An example of this in action would be www.random.org, which uses atmospheric noise as a seed.
 
Last edited:
If it was truly random then why would it not repeat, perhaps many times after all it is supposed to be random, however, computers (at least at the moment) cannot be random as such. if it did not repeat for eons then it is not random.
 
Here is my Mersenne Twister. I copied it from the Code Project. I translated it from C#.
https://www.codeproject.com/articles/5147/a-c-mersenne-twister-class



Code:
(*
    RND calculates random numbers from 0 to 1.
    RND requires two in_out variables to maintain state.
*)
FUNCTION RND : REAL
    VAR_IN_OUT
        m_z : DWORD;
        m_w : DWORD;
    END_VAR
    VAR
        u: DINT;
     END_VAR
    m_z:=DINT_TO_DWORD(36969*DWORD_TO_DINT(m_z AND 16#FFFF)+DWORD_TO_DINT(SHR(m_z,16)));
    m_w:=DINT_TO_DWORD(18000*DWORD_TO_DINT(m_w AND 16#FFFF)+DWORD_TO_DINT(SHR(m_w,16)));
    u :=  DWORD_TO_DINT( SHL(m_z,16))+DWORD_TO_DINT(m_w);
    RND :=DINT_TO_REAL(u+1)*2.328306435454494E-10+0.5;
END_FUNCTION
The code looks ugly because before 2013, IEC wanted explicit conversions between types. Now many of the conversions aren't necessary.
 
I feel like true random number generation would actually be easier in a PLC than in the average PC, because most PCs don't have real world inputs, whereas PLCs can use the noise in analog inputs and the like, much like the random.org link mentioned above. I'm sure it would take combining several AI to get enough noise to have a meaningful range, but it's a start. Wouldn't need to be connected to anything special, almost every analog has at least SOME noise, no matter how much we try to make it go away.



If you lack analog inputs, I think your next best randomness seed would be the least significant bits of the PLC clock, at least if they are nanosecond level. When your PLC program is on the order of 10ms, plus or minus a couple ms, the whole nanoseconds range is fairly random.
 
I can't remember who it was, but some large tech company used a camera looking at a wall of Lava lamps to create a random number. I think it became an actual thing. You could try that... :)
 
I feel like true random number generation would actually be easier in a PLC than in the average PC, because most PCs don't have real world inputs, whereas PLCs can use the noise in analog inputs and the like, much like the random.org link mentioned above. I'm sure it would take combining several AI to get enough noise to have a meaningful range, but it's a start. Wouldn't need to be connected to anything special, almost every analog has at least SOME noise, no matter how much we try to make it go away.



If you lack analog inputs, I think your next best randomness seed would be the least significant bits of the PLC clock, at least if they are nanosecond level. When your PLC program is on the order of 10ms, plus or minus a couple ms, the whole nanoseconds range is fairly random.

Most PCs have temperature sensors that can be used to introduce some entropy, they also use things like keypresses and mouse movement to add more entropy to the random number generator.

Also, most Intel and AMD CPUs have an internal "random" hardware noise source that feeds into the RDRAND instruction:

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

Similar Topics

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,758
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,033
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,874
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,331
Hi guys, I need your valuable suggestions about writing a module (AWL Step7) generating random integer numbers... Let's say the users define the...
Replies
19
Views
20,448
Back
Top Bottom