Probability that rolling dice that two dice sum to X New here.
I'm trying to figure out how to come up with a roll system for a game, where i want the probability of rolling N dice or rolling one dice N times and then taking the two largest outcomes, adding them together and equaling them to some value.
I'd be happy if someone could help me with either a formula, pseudocode or the likes.
Thanks.
I already tried something with binomials etc., but i'm confused about the math.
Expected result of running the aforementioned example: 70.4%
EDIT:
I might have formulated the question wrong. Instead of rolling two dies 14 times and finding the sum of the larger two equaling 12, i'd like to e.g. find the sum of the two larger dice in a roll with 14 dice that equal to 8. This might change the answer?
 A: Your example is simple:
$$
p=1-\left (\frac56\right)^{14}-\binom {14}1 \left (\frac56\right)^{13}\left (\frac16\right)\approx 0.704.$$
In this expression we have subtracted from $1$ the probabilities of having no or only one 6. The general expression will be much more complicated.

The general expression:
$$
p_X=\sum_{k=\max(1,X-K)}^{\min(K,\lfloor\frac X2\rfloor)}\sum_{n=2}^N\binom Nn
\left (\frac1K\right)^n
\left (\frac{k-1}K\right)^{N-n} n^{1-\delta_{k,\frac X2}},
$$
where $X$ is the sum which probability is to be computed, $K$is the number of dice faces (numbered from $1$ to $K$), $N$ is the number of rolls, $\delta$ is Kronecker delta, $\lfloor x\rfloor$ is the floor function.

Explanation of the formula:
Let the two largest numbers be $k$ and $k'$ ($1\le k\le k'\le K$, $k+k'=X$). Any other result of a trial, $k''$, should be either less or equal to $k$. To avoid over-counting it is suggestive to consider the arrangements with distinct amount of trials giving the result "$k$" separately and then sum the resulting probabilities. This idea is implemented in the formula in the following way:
The first sum runs over all possible values of $k$.  The limits of summation are chosen to ensure $k'=X-k\ge k$. The limits also take care of the finite set of allowed values $(1..K)$ for $k$. In the next sum each $n$ represents the cardinality of a multiset consisting of one $k'$ and $(n-1)$ $k$-numbers. The multiset can be placed in the overall result of $N$ trials in $\binom Nn$ ways ($k$ and $k'$ are assumed for a moment to be indistinguishable). The probability that the final result contains such a multiset is $\left (\frac1K\right)^n\left (\frac{k-1}K\right)^{N-n}$, where the last factor stays for the probability to fill the rest $(N-n)$ places with numbers $k''<k$. Finally, if $k\ne k'$ (which is equivalent to $k\ne\frac X2$), one among $n$ places chosen for the multiset shall be filled with $k$. This can be done in $\binom n1=n$ ways, and this is the last factor in the expression.

Hope this helps.
A: This is the same as the answer I gave to the now closed https://stats.stackexchange.com/questions/399396/probability-that-rolling-n-dice-that-the-two-larger-dice-sum-to-x/399409#399409.
Here is a program to solve the question:
import fractions

# The usual recursive factorial implementation.
def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

# The standard formula for n choose m
def choose(n, m):
    return factorial(n) / factorial(m) / factorial(n-m)

# The number of ways to get a roll given a number of dice
# of a given size.
def num_dice_outcomes(num_of_dice, dice_size):
    return dice_size**num_of_dice

# Recursive way to calculate rolling the dice and coming to a
# specific answer.  Note, the cache uses memoization to make it
# faster.
cached_dice_outcomes = {}
def num_dice_outcomes_of_result(num_of_dice, dice_size, result):
    # First the trivial answers.
    if result < num_of_dice:
        return 0
    elif num_of_dice * dice_size < result:
        return 0
    elif num_of_dice < 0:
        return 0
    elif num_of_dice < 2:
        # Either 0 from 0 dice, or something in the range
        # 1..size_of_dice from 1 die.  Either way there is 1 way.
        return 1
    else:
        # The answer depends only on t.
        t = (num_of_dice, dice_size, result)
        # If we don't have a cached answer
        if t not in cached_dice_outcomes:
            answer = 0
            # For each possible roll of the first die
            for i in range(1, dice_size + 1):
                # We add the number of ways that the rest adds up.
                answer = answer + num_dice_outcomes_of_result(num_of_dice - 1, dice_size, result - i)
            # And now cache it so that we don't repeat this calculation.
            cached_dice_outcomes[t] = answer
        return cached_dice_outcomes[t]

# This is the function that computes our answer.  We will calculate
# the number of ways to get the right answer over the number of
# possible dice outcomes.
def prob_of_sum(result, num_of_dice, top_n_dice=2, dice_size=6):
    # Get the number of possible dice outcomes.
    total_count = num_dice_outcomes(num_of_dice, dice_size)

    # Now count the number of outcomes that get the result.
    result_count = 0
    # cutoff is the smallest roll we will include in our top n dice.
    # It is in the range 1..dice_size.
    for cutoff in range(1, dice_size + 1):
        # How more do we need to get from the dice that are above
        # our cutoff?
        result_above = result - cutoff * top_n_dice
        # We can have 0..(top_n_dice - 1) dice above the cutoff.
        for dice_above in range(top_n_dice):
            # How many ways do the dice above get to the needed
            # result above?
            ways_above = num_dice_outcomes_of_result(dice_above, dice_size - cutoff, result_above)
            # How many combinations of dice can be part of our dice above?
            ways_dice_above = choose(num_of_dice, dice_above)
            # How many dice are at our cutoff?  This includes all of
            # the top n that are not above, plus any number of the rest.
            # That range works out to be:
            #   (top_n_dice - dice_above)..(num_of_dice - dice_above)
            for dice_at_cutoff in range(top_n_dice - dice_above, num_of_dice - dice_above + 1):
                # How many ways can we choose which dice are at the cutoff?
                ways_dice_cutoff = choose(num_of_dice - dice_above, dice_at_cutoff)
                # How many ways can the dice below the cutoff be rolled?
                ways_dice_below = num_dice_outcomes(num_of_dice - dice_above - dice_at_cutoff, cutoff-1)
                # We now know the number of ways to get this result from
                # this cutoff, this many dice_above cutoff, and this many
                # dice_at_cutoff.
                this_ways = ways_above * ways_dice_above * ways_dice_cutoff * ways_dice_below
                # Add that to our running total.
                result_count = result_count + this_ways
    # We return a fraction to get exact arithmetic, even if the numbers
    # involved are very large.
    return fractions.Fraction(result_count, total_count)

# We print our answer as a float for convenience.
print(float(prob_of_sum(12, 14, 2, 6))) # 0.704031049874

A: I assume throughout that the die used is $6$ sided.
Taking each value of $X$ separately there are $11$ possible values the 'larger sum' can take - $\{2,3,4,5,6,7,8,9,10,11,12\}$. In order to achieve $X=2$ in $n$ rolls of the die, one must roll $n$ $1$s which has a probability of $\frac1{6^n}$ of occurring. For $X=3$ one must roll a single $2$ and otherwise $1$s. The probability of this occurring is $\binom{n}{1}\frac{1}{6^n}=\frac{n}{6^n}$ because the $2$ can be rolled in any of the $n$ rolls and there are $n$ total rolls occurring with a probability of $\frac16$ of occurring. For $X=4$ one can roll any number of $2$s greater than or equal to two and otherwise roll a $1$. The probability of this occurring is equal to $\frac1{3^n}-\frac{1+n}{6^n}=\frac{2^n-n-1}{6^n}$ because this is just equal to the probability of rolling $n$ $1$s or $2$s and not rolling either all $1$s or only one $2$ ($X=2$ and $X=3$ respectively). One can continue like this to formulate every possibility up to $X=12$.
