I came across this interesting question on another StackExchange sub that has not been answered after a couple of years. After searching Meta for protocol and finding this post, I think it's appropriate to cross-post here.
I have duplicated the original question verbatim below.
Background
I found this interesting question https://stats.stackexchange.com/questions/130025/formula-for-dropping-dice-non-brute-force/242839 and excellent answer https://stats.stackexchange.com/a/242857/221422, but couldn't figure out how to generalize a generating function for when more than one die is dropped. Similarly, I'm having difficulty figuring out a related mechanic for when the highest roll is dropped.
Description of the Problem
Suppose you have $N$ fair dice each with $S$ sides. Roll all the dice and then remove the lowest [or highest, alternatively] $M$ (where $M > 0$ and $M < N$) dice and then sum the remainder. What is the probability distribution of the sum? Specifically, how does one go about finding the generating polynomial?
Implementation of whuber's answer
I found whuber's answer to be incredibly thorough. I thought it might be nice to see how to actually implement it in code, so I've pasted that below.
from functools import reduce
from numpy.polynomial import polynomial as p
def generating_function(k, d, n):
return p.polypow(
[0] * k + [1] * (d - k + 1),
n
)
def drop_one_die(n, d):
tmp = [
generating_function(k, d, n) for k in range(1, d + 2)
]
differences = (
(tmp[i] - tmp[i + 1])[i + 1:] for i in range(d)
)
return reduce(p.polyadd, differences)
print(
drop_one_die(4, 6)
)
Other considerations / Multinomial distribution
To generalize even further, instead of a fair die where each outcome is equally likely, what if you start with a general multinomial distribution?
So instead of
$$(1/6)x + (1/6)x^2 + (1/6)x^3 + (1/6)x^4 + (1/6)x^5 + (1/6)x^6$$
you start with
$$p_0 + {p_1}{x} + {p_2}{x^2} + ... + {p_n}{x^n}$$
Thanks!

This is simply a naive generalization of whuber's approach. I'm skeptical about whether there will be anything better as far as exact answers go. Certainly there are asymptotics in various regimes, e.g. whuber already noted a Central Limit Theorem experimentally.
For simplicity, consider dropping $2$ out of $n$ $d$-sided dice. Let $f_{n, d, k_1, k_2}(x)$ be the ordinary generating function for the sum of $n$ dice where the smallest is at least $k_1$ and the second-smallest is as least $k_2$. Then $$f_{n, d, k_1, k_2}(x) = (x^{k_1} + x^{k_1+1} + \cdots + x^d)(x^{k_2} + \cdots + x^d)^{n-1} = x^{k_1 + (n-1)k_2} \left(\frac{1-x^{d-k_1+1}}{1-x}\right) \left(\frac{1-x^{d-k_2+1}}{1-x}\right)^{n-1}$$
We want the OGF for the sum of the $n-2$ largest dice where the smallest is exactly $k_1$ and the second-smallest is exactly $k_2$. Well, that's just $$g_{n,d,k_1,k_2}(x) = x^{-k_1-k_2} \begin{cases} f_{n, d, k, k}(x) - f_{n, d, k+1,k+1}(x) & \text{if }k_1 = k_2 = k \\ f_{n, d, k_1, k_2}(x) - f_{n, d, k_1+1, k_2} - f_{n, d, k_1, k_2+1}(x) & \text{if }k_1 < k_2 \end{cases}$$
So, your probability generating function is $$\frac{1}{n^d}\sum_{1 \leq k_1 \leq k_2 \leq d} g_{n, d, k_1, k_2}(x).$$
Clearly this generalizes to dropping $m$ of the dice. The final sum will have $O(d^m)$ terms, so it scales exponentially in $d$.