# Random Within Random Probabilities

Printable View

• Apr 8th 2010, 11:47 AM
DarthRiko
Random Within Random Probabilities
I fancy myself a programmer, and I've created a bit of code including a randint(randint(1,6),6). For those of you who don't speak the same language I do, it basically finds a random integer from 1 to 6, and then finds a random integer from that number and 6 again.
Once I got done with the bit I was using it for, I got curious as to the probabilities of it returning certain numbers.
I tried doing some simple math in my head, but my brain kept throwing in the fact that there is no such thing as true randomness in programming, and my math kept getting super complicated, and ultimately wrong. So I googled for a math help forum and came here.
Can anyone tell be the probabilities of my formula returning each number from 1 to 6?
• Apr 8th 2010, 01:05 PM
Opalg
Quote:

Originally Posted by DarthRiko
I fancy myself a programmer, and I've created a bit of code including a randint(randint(1,6),6). For those of you who don't speak the same language I do, it basically finds a random integer from 1 to 6, and then finds a random integer from that number and 6 again.
Once I got done with the bit I was using it for, I got curious as to the probabilities of it returning certain numbers.
I tried doing some simple math in my head, but my brain kept throwing in the fact that there is no such thing as true randomness in programming, and my math kept getting super complicated, and ultimately wrong. So I googled for a math help forum and came here.
Can anyone tell be the probabilities of my formula returning each number from 1 to 6?

The first randint(1,6) returns each of the numbers 1,2,...,6 with a probability of 1/6. The only way that the second randint can return a 1 is if the first randint is a 1 (probability 1/6) and so is the second (probability again 1/6. These probabilities have to be multiplied, so the probability of the combined process returning a 1 is $1/36\approx 0.028$.

To get a 2 from the combined process, you either need a 1 first time (prob. 1/6) and then a 2 (prob. again 1/6); or you get a 2 first time (prob. 1/6) and then another 2 (prob. 1/5 this time, because there are only the five numbers 2,3,...,6 to choose from). So the probability of the combined process returning a 2 is $\tfrac16\bigl(\tfrac16+\tfrac15\bigr)\approx 0.061$.

Continuing in that way, the probability for each of the remaining numbers being returned by the combined process is:

prob. that it is 3 is $\tfrac16\bigl(\tfrac16+\tfrac15+\tfrac14\bigr)\app rox 0.103$,
prob. that it is 4 is $\tfrac16\bigl(\tfrac16+\tfrac15+\tfrac14 +\tfrac13\bigr)\approx 0.158$,
prob. that it is 5 is $\tfrac16\bigl(\tfrac16+\tfrac15+\tfrac14+\tfrac13+ \tfrac12\bigr)\approx 0.242$,
prob. that it is 6 is $\tfrac16\bigl(\tfrac16+\tfrac15+\tfrac14+\tfrac13+ \tfrac12+1\bigr)\approx 0.408$.

As a check, you can add the six probabilities and see that their sum comes to 1.
• Apr 8th 2010, 01:28 PM
DarthRiko
I'm not very good with writing thank yous, so my gratitude won't be fully expressed. Still, thanks.