Probability of getting 3 red balls out of 9 attempts any order This is a follow up of this question as I think I have been able to simplify the goal: 3x3 Scratch and Win
Assume you have a bag with


*

*red balls with a probability of r% (e.g. 25%)

*black balls with a probability of n% (e.g. 75%)


Assume you pick balls one by one (and return them after to the bag, so probability of getting a red/black ball never changes).
If a user randomly gets a ball from the bag 9 times:


*

*what is the probability of getting 3 OR MORE red balls? Order does not matter.

*how this probability relates to r%, i.e. formula with r% as variable

 A: Suppose we have $R$ red balls and $B$ black balls. Then the probability of drawing a red ball is $p_R:= \frac R{R+B}$ and the probability of drawing a black ball is $p_B:= \frac B{R+B}$. Let $X_i\stackrel{\mathrm{i.i.d.}}\sim\mathrm{Ber}(p_R)$, $i=1,2,\ldots$ and define $S_n = \sum_{i=1}^n X_i$ for $n=1,2,\ldots$. Let $k$ be a nonnegative integer and $m$ a positive integer. Then
$$
\mathbb P(S_m\geqslant k) = \sum_{i=k}^m \binom mi p_R^i p_B^{m-i} = \sum_{i=k}^m \binom mi \left(\frac R{R+B}\right)^i\left(\frac B{R+B}\right)^{m-i}.
$$
In our example we have $k=3$ and $m=9$, so
$$
\mathbb P(S_9\geqslant 3) = \sum_{i=3}^9 \binom 9i\left(\frac R{R+B}\right)^i\left(\frac B{R+B}\right)^{9-i} = 1-\frac{B^7 \left(B^2+9 B R+36 R^2\right)}{(B+R)^9}.
$$
We can write this in terms of $p_R$ and $p_B$ as follows:
$$
1-\frac{B^7 \left(B^2+9 B R+36 R^2\right)}{(B+R)^9} = 1 - p_B^7(p_B^2 + 9p_Bp_R + 36p_R^2).
$$
In the case where we only know $p_R$ and $p_B$, and not the actual values of $R$ and $B$, the probability is given by
$$
p_R^3 \left(126 p_B^5 p_R+126 p_B^4 p_R^2+84 p_B^3 p_R^3+36 p_B^2 p_R^4+9 p_B p_R^5+84 p_B^6+p_R^6\right).
$$
A: Just if someone is interested, following @lioness99a and @N. F. Taussig answers:
import org.apache.commons.math3.distribution.BinomialDistribution;

public class ScratchAndWin {
    public static void main(String[] args) {

        double PROBABILITY_RED = 0.10; // <--- change this
        int EXTRACTIONS = 9;
        int REQUIRED_SUCCESSES = 3;

        BinomialDistribution distribution = new BinomialDistribution(EXTRACTIONS, PROBABILITY_RED);
        double percentaje = 1 - distribution.cumulativeProbability(REQUIRED_SUCCESSES - 1);
        System.out.println("PERCENTAGE WINNERS 3 REDS: " + percentaje);
    }
}

