• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

dynamic odds calculation

CloseRange

Member
So i just need to know how to calculate the overall odds of this dynamic odds (idk what else to call it)
how it works.
The odds start out as 1/n
any time the random check fails, n is decremented
any time the random check succeeds, n is reset.
so it looks something like this:
Code:
var oddsMax = 9;
var n = oddsMax;
repeat(100) {
   if(random(1) <= 1/n) {
      n = oddsMax;
   } else n--;
}
i know I can calculate this via code by tracking how many times it succeeds / total trys
however I need a mathy way to do it so I can reverse it and figure out what to set oddsMax to in order to get an overall 50% chance or whatever I need.
 

Yal

šŸ§ *penguin noises*
GMC Elder
odds of success = successes / total tries

You know desired odds and the number of tries, so you could get OddsMax by plugging those in into the equation and solve for the unknown value, right?
 

CloseRange

Member
That's true when the events are independent of each other. These are dependent.
the odds of one event could be 1/9 but the next event could be either 1/8 or 1/9, depending on if the first event passed or not.
the third try could be either 1/7, 1/8, or 1/9 odds depending on the first 2 events

I know how to solve independent events, that's easy enough. But my memory of discrete math is fuzzy with the whole dependent events.
Unless i'm understand what you said wrong.
 

Nidoking

Member
Let me give this a go. Let P(a) be the probability that attempt a is a success. Then:
P(1) = 1/n
P(2) = (1 - 1/n) * 1/(n-1) Get a common denominator for the first term and you get (n-1)/n * 1/(n-1). (n-1) cancels, and you're left with P(2) = 1/n
P(3) = (1 - (1/n + 1/n)) * 1/(n-2) Combine terms to get (1 - 2/n) * 1/(n-2) = (n-2)/n * 1/(n-2) = 1/n

So for all a, P(a) = 1/n. Therefore, the combined total of P(1) + P(2) + P(3) + ... + P(c) = c/n. For overall probability p, c = n*p. If you want a 50% probability within the first c attempts, c = 0.5n.

EDIT: On second thought, you're going to continue rolling until you hit 100 attempts, and you want an average of 50 successes. That's a very different calculation, especially since with n=2, you're guaranteed at least 50 successes, because every failure is followed by a guaranteed success. I'll think about it some more, but the above method might be useful as a starting point.
 

CloseRange

Member
I figured it out... I don't have a proof for it but... well it works...
if I have oddsMax = 9;
the overall odds is 1 / ((oddsMax+1)/2)
and if I want, let's say, a 50% chance of success I'd say:
Code:
oddsMax = 2 / (.5) -1;
 

Nidoking

Member
Yes, I believe that's correct. I figured out a simpler way to think about it, since directly calculating the probability of success on a given attempt wasn't working. However, as I showed above, the probability that your FIRST success will be on any given attempt is a flat curve - it's always 1/n, where n is your oddsMax. So, with a large number of iterations like 100, what you want for 50% success is 50 successes, therefore an average of two attempts for success following any success. Given n=3, then, the distribution is 1/3 success in one attempt, 1/3 success in two attempts, and 1/3 success in three attempts. The average number of attempts is two. The average number of attempts given any n is (n+1) / 2, so setting 2 = (n+1)/2 gives 4 = (n+1), n = 3 = 2/(.5) - 1.
 
Top