Skip to main content
GameDev.net gamedev.net
🔒 Locked

Probability question

Started by Jamiernmd Jun 8, 2010 at 6:53 AM 7 replies 900+ views
Original Post
Jamiernmd
Jamiernmd
Hi all,

I'm trying to work out the probabilty of obtaining 1, 2, 3 etc balls in a lottery game. However the numbers are predetermined. So how do I work out the probability of, for example (1,2,3,4,5,6) appearing and more specifically how do I work out the probably of just 1,2,3 etc balls being correct.

I initially thought the probabilty of 1 ball occuring was 6/60 but obviously this is incorrect. The only other way I have so far found of doing it (with one correct ball) is to establish the odds of one specific combination occuring with one correct ball, and then multiplying this by the total number of combinations containing one ball, but this seems a little long-winded. Is there a better solution?

Cheers
alvaro
alvaro
Not all lotteries work the same way, so you are going to have to explain how yours works.
Jamiernmd
Jamiernmd
There are 60 balls, and 6 are drawn. No bonus balls to worry about. The order of the balls doesn't matter.

Ideally I want to pass in a 'ticket' run the application 1 million times and it returns both the odds and the actual result of getting 1 through 6 numbers correct.

cheers
Wan
Wan
You mean this?
1st draw: 6 out of 60 (6/60)2nd draw: 5 out of 59 (5/59)3rd draw: 4 out of 58 (4/58)4th draw: 3 out of 57 (3/57)5th draw: 2 out of 56 (2/56)6th draw: 1 out of 55 (1/55)
Edit: see lottery mathematics
alvaro
alvaro
And I am guessing you pick 6 numbers. Well, the probability of getting all 6 right is easy to compute. When the first ball is drawn, it has to be one of yours, and this has probability 6/60. Then the next ball is drawn, and there are 59 balls left of which 5 will make you happy. So the second ball will still keep our hopes up with probability 5/59. Similarly the next balls are 4/58, 3/57, 2/56 and 1/55. And then we won. So the probability of all this happening is
(6/60)*(5/59)*(4/58)*(3/57)*(2/56)*(1/55) = 6!/(60!/54!) = 6!54!/60! = 1/C(60,6)

The probability of getting none is also easy. The first ball has to be one of 54 numbers you didn't pick, so the probability of that happening is 54/60. The next one it will be 53/59, then 52/58 and so on.

For the cases in between, you can consider a little tree of possibilities. Try it for getting 5. The first ball will be one of yours with probability 6/60, as before, but even if you don't get it, you may still get your 5 numbers, so don't despair. You compute the probability of getting 5 given that the first ball was one of yours (P), and the probability of getting 5 given that the first ball was not one of yours (Q). Then the total probability will be 6/60*P+54/60*Q.

Once you understand how this works, I would program it using dynamic programming. The idea is to write a function P(H,N,M) that can compute the probability of getting exactly H hits in a lottery with N balls of which you pick M. You can implement this recursively as I just described in the previous paragraph. This will probably take a prohibitive amount of time, but notice that you will be computing the function with the same arguments over and over again. So if you memoize the function, you'll effectively get a fast dynamic-programming solution.

Ezbez
Ezbez
The chance the first ball is a given number is 1/60. The chance the second one is a given number (given that the first ball is already taken) is 1/59. Then 1/58, 1/57, 1/56, and 1/55. Multiply them together, and you get the probability that six numbers are chosen, in order.

Now, basic combinatorics says that there are 6*5*4*3*2*1 (or 6 factorial) ways to order those six numbers. Since each order is entirely disjoint from the others (that is, no outcome could be considered to be in two or more orderings), we can add their probabilities together to get the probability that any of them occur. Since they all have the same probability (from above paragraph), we can just multiply the number of orders with the probability of a single one occurring.

So the answer would be 6*5*4*3*2*1/(60*59*58*57*56*55).
GWDev
GWDev
Hi,

sorry don't have much time, but this should give you an idea.

http://en.wikipedia.org/wiki/Hypergeometric_distribution

--GWDev
alvaro
alvaro
Actually, the problem is small enough that what I suggested above runs fast even without memoization:
#include <iostream>double P(int H, int N, int M) {  if (M==0)    return H==0 ? 1.0 : 0.0;  double inv_N = 1.0/N;  return M*inv_N*P(H-1,N-1,M-1)+(N-M)*inv_N*P(H,N-1,M-1);}int main() {  for (int i=0; i<=6; ++i) {    std::cout << i << ' ' << P(i,60,6) << '\n';  }}
Jamiernmd
Jamiernmd
Ok, I think I'm in a better position to understand it all now. Thanks very much for all your help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.