OT: Random Number Generator

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.

Hi, that's actually a good point. However, since numbers are infinite, then one would probably want to have some limits, especially if one built a hardware RNG.
So say one ran the generator 24/7 for exactly one month and it produced a number every 3 seconds. If one had 1 number that repeated as an example 4 times in that period, then wouldn't something be wrong? Say the limits were +/- 1,000,000. What if 4 numbers repeated? Maybe one 3 times, one 1 time and so forth. Just thinking out loud here. This is fun.
 
The mention of gaming machines & the use of random, in the early 80's I did a lot of work in that industry, although not specifically on fruit machines or other AWP (Award with prizes), mainly on repair & upgrading the likes of Space invaders & all the newer types of machines, I did learn that during the boom of using stepper drives controlled by microprocessors rather than pure electro-mechanical systems there was as such no randomness as far as pay out.
These machines could be set to pay out a percentage of coinage put in.
In other words, a machine could be programmed to pay out 74% (think this was the allowable range for a licence) of the coinage throughput, the pay out percentage was mainly controlled by the features system i.e. perhaps if the money in versus the money out was 75% or above it would enable the features, this resulted in a larger than normal pay out via the feature.
I do remember some trials (I was not involved), where a group of people played these machines, it was obvious that most people win a little put it back so for example for every amount of coinage in only 75% is paid out, in reality the actual pay out is probably 0.001% as people put back any winnings in the hope of a big game. In essence if £10.00 is played it is possible £7.50 is paid out, this is then put back in & so the average pay out will be 75% of that £7.50 & so on.
Yes there may have been some sort of pseudo random algorithm but it was strictly controlled, I worked with a guy who was in a team who developed a new style of gaming called award with skill, this in essence would get round the gaming laws & controls for example no licence needed or the current controls, there was a very long & expensive court case in a part of the UK regarding this, the outcome appeared to favour the developers, in other words it was not gambling but awards were based on skill so could not be classed as gambling. One feature of this was to effectively control the pay out so that the machine never actually lost was the prize started off low for example if 50 pence was the stake then the pay out would start at £1.00, as the money throughput increased, though no winners this increased surpassing the pay out limits of the current gambling legislation, however, once won the jackpot would revert back to the lower level. as this was not gambling then the jackpot could be very high.
I did meet a guy who was an expert on the second world war, there was a game based on questions for that era, his nights out consisted of going round the bars, waiting for a reasonable jackpot & win most of the time, it was reckoned that he made a good living out of it.
 
What kind of use case would require a RNG ? I like the concept of using them in gaming machines. I wonder if there's any other situation.


I've seen it needed for demo systems, when you're simulating a system but want the trends to not be perfectly straight lines, or need a fake disturbance for it to correct.
 
What kind of use case would require a RNG ? I like the concept of using them in gaming machines. I wonder if there's any other situation.

I know that segment I saw years ago about that guy that was implementing an RNG in gaming equipment (slots) was pretty cool. He designed a way to defeat it by putting so many credits in and then doing that in a sequence etc. I guess there were some large payouts. I don't remember how he got caught.

I think it would be good in the lottery. Or even bingo. Instead of those ping pong balls.
 
Hi, that's actually a good point. However, since numbers are infinite, then one would probably want to have some limits, especially if one built a hardware RNG.
So say one ran the generator 24/7 for exactly one month and it produced a number every 3 seconds. If one had 1 number that repeated as an example 4 times in that period, then wouldn't something be wrong? Say the limits were +/- 1,000,000. What if 4 numbers repeated? Maybe one 3 times, one 1 time and so forth. Just thinking out loud here. This is fun.
Random number generators usually generate a number that is scaled to what ever you want. Must common is scaling from 0 to 1.

Here is a question. First lets simplify. Lets say the number range is from 0 to 99 and the probability distribution is flat or even for all numbers. What are the chances of get the same number 2 times when taking only 10 samples?
This is a rather basic probability problem.
A little harder, maybe a lot harder, is what are the chances of getting 4 numbers the same.





drbitboy would probably just use python to do many tests to get the answer.



BTW, I use random number generators all the time to test for robustness of control. A few month back I used a random number generator to show why the dead band on a PID or floating control should not be so wide that the noise doesn't go outside the dead band.
 
Philosophically speaking, is anything truly random?
Suppose the big bang is real with all matter forced into a singularity. If you know all variables for matter then one should be able to calculate everything leading up to now - and even predict the future. Alas, we do not posses all variables nor the computing power for this.

I propose the mandatory xkdc:
Code:
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
 }
 
Lets say the number range is from 0 to 99 and the probability distribution is flat or even for all numbers. What are the chances of get the same number 2 times when taking only 10 samples?
This is a rather basic probability problem.

Yes, that is the well-known Birthday Problem, cf. this link. Also, I think it's only basic if it's stated as "get the same number at least 2 times."

A little harder, maybe a lot harder, is what are the chances of getting 4 numbers the same.


Ooh, darn it, now I won't get any work done today.


drbitboy would probably just use python to do many tests to get the answer.

Yes, Monte Carlo is in my toolkit (along with the duct tape;)), but only to check the analytical solution.
 
Last edited:
Philosophically speaking, is anything truly random?
Suppose the big bang is real with all matter forced into a singularity. If you know all variables for matter then one should be able to calculate everything leading up to now - and even predict the future.

Let us say that I flip a fair coin, look at it myself without revealing it to you, and then ask you to guess which way up it landed. Is it random whether you will guess correctly?

If your supposition is philosophically accurate, then the answer should be 'no'. After all, even if the act of flipping the coin itself is 'random,' the state of the coin after it has landed is fixed and known. And yet on average 50% of the time you will guess incorrectly, exactly as we would expect from a state of reality in which true randomness exists.

P.S. the xkcd is humorous in part because the method does in fact return a 'randomly chosen number' (assuming we accept the die roll as random); it just never picks a new number. It does exactly what it says it does, while being useless for what you'd expect to use something labelled that for.

EDIT: P.P.S. I well remember working out the math for the birthday problem in my youth after encountering it in the Saint series (the books, not the TV series or film).
 
Random number generators usually generate a number that is scaled to what ever you want. Must common is scaling from 0 to 1.

Here is a question. First lets simplify. Lets say the number range is from 0 to 99 and the probability distribution is flat or even for all numbers. What are the chances of get the same number 2 times when taking only 10 samples?
This is a rather basic probability problem.
A little harder, maybe a lot harder, is what are the chances of getting 4 numbers the same.





drbitboy would probably just use python to do many tests to get the answer.



BTW, I use random number generators all the time to test for robustness of control. A few month back I used a random number generator to show why the dead band on a PID or floating control should not be so wide that the noise doesn't go outside the dead band.

That's cool using one for a PID test. I'm still thinking about what Parky said, that if a number doesn't repeat, then the generator is probably not random. It would be like having a logic program that was running a process and then program it so it would select any number except one already used. Maybe something with a range of -50 to +50 and then reset when all were used. That would not be random it would be software to eliminate duplicate numbers, like we use in faults and so forth.
 
Something i had decent results in without a supercomputer was have a PLC with 4 timers with different presets.


Then 4 counters counting each when a different timer was /DN - counter preset 10, when that counter was /DN reset it.


Have a 5th counter on Every-Other-Scan with a preset of 4, when /DN reset it
Use the 5th counter Accumulator to grab the Accumulator of one of the 4 timers and save it. This grabbed a very random single digit number.



Have a 6th counter Every-Other-Scan count to a preset of the number of digits in the "random" number and place the saved value in that position's holding integer.


Multiply all the integers to their base and add together (N7:1 + (N7:2*10) + (N7:3*100) + ......) and I had a number that was dooable as long as it wasn't checked too soon, as then only a few digits may have changed. On mine I checked it about every 2 minutes so it had changed all digits more than once.
 
Here is a question. First lets simplify. Lets say the number range is from 0 to 99 and the probability distribution is flat or even for all numbers. What are the chances of get the same number 2 times when taking only 10 samples?
This is a rather basic probability problem.
A little harder, maybe a lot harder, is what are the chances of getting 4 numbers the same.

Using data from random.org and Excel (and VBA) I did 10k samples of 10 integers from 0-99.

A single double occurred in 3157 samples
A double double (2 doubles, different numbers) occurred in 495 samples
A triple double (3 doubles, different numbers) occurred in 24 samples
Any double occurred in 3676 samples

A single triple occurred in 118 samples

A single quad occurred in 2 samples.

Need more data to comment on triples and quads but occurrence of any double (not including triples etc.) is about 36.7%

Random.org only lets you get 10000 integers at a time so it gets labor intensive after a while of cut paste.
 
Let us say that I flip a fair coin, look at it myself without revealing it to you, and then ask you to guess which way up it landed. Is it random whether you will guess correctly?

If your supposition is philosophically accurate, then the answer should be 'no'. After all, even if the act of flipping the coin itself is 'random,' the state of the coin after it has landed is fixed and known. And yet on average 50% of the time you will guess incorrectly, exactly as we would expect from a state of reality in which true randomness exists.


Well my "thought experiment" would indicate that the coin was already destined to land in a certain position and could be predicted if all *data* was known and calculated.
Also my guess, whether right or wrong, would also not be random.


Like a movie you are watching, it is already fixed, you just havent seen it yet so every scene is "random" to your eyes.
 
So just a thought as I have not tried it...

But how about using the PLC scan time? this should vary and not be the same if you can get a large enough time/number, if the PLC shows 3ms all the time it will not work but if it shows 3.11, 2.83, 3.06 and then use that number to set a time base or a set point, then couple counters/timers thrown into the mix you should have a random number, in a range not a true 16bit random number but is should be a variable that will not repeat the same pattern, you will get the same number but not a pattern
 
Well my "thought experiment" would indicate that the coin was already destined to land in a certain position and could be predicted if all *data* was known and calculated.
The key being 'all *data* was known and calculated.' If the uncertainty principle is true, it is simply impossible for this to be the case -- limits to our ability to measure (and thus know or calculate) are a fundamental property.

ojz0r said:
If you know all variables for matter then one should be able to calculate everything leading up to now - and even predict the future.

Heisenberg tells us that even if you know the starting conditions, there are limits to how accurately current values can be known.
 

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,769
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,882
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,341
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,651
Back
Top Bottom