How to determine probability of an outcome when the number of tries is variable. Given a known probability of an event being successful, how do you calculate the odds of at least one successful outcome when the number of times you can attempt is determined by a separate dice roll.
For example:  I know the probability of a favorable outcome on dice X is "P".      I first roll a six sided dice. That dice roll determines the number times I can roll dice X.  What is the probability that I will have at least one successful roll of dice X as a function of "P"?

*

*If you roll the X die $k$ times, the probability of failing on all $k$ times  is $(1-p)^k$.


*Hence the probability of succeeding at least once in $k$ tries is $1-(1-p)^k$. (because succeeding at least once and failing every time are complementary events.)


*Because the initial die roll is independent of the X die roll, their probabilities multiply. The probability of succeeding when you roll a six-sided die then roll your X die that many times is:
$$\sum_{k=1}^6 \frac{1}{6}\times \left[1-(1-p)^k\right] = 1-\frac{1}{6}\sum_{k=1}^6(1-p)^k$$


*The geometric sum formula states that $\sum_{k=1}^n q^k = \frac{q(1-q^n)}{1-q}$.  In our case, this means that the overall probability of success with a $n=6$ sided die and $q=(1-p)$ geometric probability is:
$$1-\frac{1}{6}\frac{(1-p)(1-(1-p^6))}{p},$$ which, if you like, is just the polynomial
$$\Pr(p) = -\frac{1}{6}\left(p^6 - 7p^5 + 21 p^4 -35 p^3 + 35 p^2 - 21 p^1 \right)$$


*As an example, when $p=\frac{1}{2}$ (X is a two-sided coin), the probability is around 0.83. When $p=\frac{1}{6}$ (X is another six-sided die), the probability is around 0.45.
