To have **at most** two disciplines occurring, one can have either only $1$ discipline or $2$ disciplines showing. Also, since this is sampling with replacement, we can consider the draws to be of three objects $(M, H, G)$ with probability $(\frac{4}{8}, \frac{3}{8}, \frac{1}{8})$ respectively.

For brevity, let's deal only with the numerators, as the denominator of the five draws will be $8^5$. Now the way to have only one discipline is relatively straightforward. It is a fivefold draw of the same value, so we can start with:
$$
M^5\Rightarrow 4^5 = 1024\\
H^5\Rightarrow 3^5 = 243\\
G^5\Rightarrow 1^5 = 1
$$
Now the case of two disciplines can be broken into four classes. If $A$ is the first discipline and $B$ is the second, we can have patterns of the form $AAAAB$. We also need to consider the order in which these books were picked. For example, $AABAA \equiv AAAAB$ so we need to factor in the number of unique orders in which these patterns can occur. When we have $n$ elements which can be broken into $k$ distinct groups with size $n_i, \sum_k{n_i} = n$, the number of permutations is:
$$
{n \choose {n_1, n_2, \ldots, n_k}} = \frac{n!}{n_1! n_2! \ldots n_k!}
$$
The list of patterns and their permutations are
$$
AAAAB \Rightarrow A^4B^1; {5 \choose {4, 1}} = 5\\
AAABB \Rightarrow A^3B^2; {5 \choose {3, 2}} = 10\\
AABBB \Rightarrow A^2B^3; {5 \choose {2, 3}} = 10\\
ABBBB \Rightarrow A^1B^4; {5 \choose {1, 4}} = 5
$$

There are also ${3 \choose 2} = 3$ ways to select $A$ and $B$ from $(M, H, G)$, so there will be $12$ cases for us to enumerate:
$$
MMMMH \Rightarrow 4^41^1\cdot 5 = 3840\\
MMMHH \Rightarrow 4^31^2\cdot 10 = 5760\\
MMHHH \Rightarrow 4^21^3\cdot 10 = 4320\\
MHHHH \Rightarrow 4^11^4\cdot 5 = 1620\\
MMMMG \Rightarrow 4^41^1\cdot 5 = 1280\\
MMMGG \Rightarrow 4^31^2\cdot 10 = 640\\
MMGGG \Rightarrow 4^21^3\cdot 10 = 160\\
MGGGG \Rightarrow 4^11^4\cdot 5 = 20\\
HHHHG \Rightarrow 3^41^1\cdot 5 = 405\\
HHHGG \Rightarrow 3^31^2\cdot 10 = 270\\
HHGGG \Rightarrow 3^21^3\cdot 10 = 90\\
HGGGG \Rightarrow 3^11^4\cdot 5 = 15
$$
So we have a total of $19,688$ acceptable draws out of $32,768$ total, which simplifies to:
$$
\frac{2461}{4096} = 1 - \frac{1635}{4096}
$$
Which matches what @whuber wrote. That highlights one of the beauties of combinatorics. It all boils down to *counting* so all the sophisticated methods, such as generating functions, **must** jibe with simple, but exhaustive, enumeration. Hope this helps.

For greater generality, let's say that there are $n$ people and $m$ values to choose from. If you are given the chosen values $U_1,...,U_n$ then the deterministic formula for the number of values that were chosen is:

$$K \equiv \sum_{k=1}^m \mathbb{I}(Y_k > 0)
\quad \quad \quad \quad \quad
Y_k \equiv \sum_{i=1}^n \mathbb{I}(X_i = k).$$

The value $K$ is called the **occupancy statistic** and it is the number of unique values that were chosen out of the $m$ values (so it has range $1 \leqslant K \leqslant \min(n,m)$). This value is a deterministic function of the underlying values that were chosen. In a statistical context, if we assume that the values are chosen independently and are uniform over the possible choices then we have $U_1,...,U_n \sim \text{U} \{ 1,...,m \}$ and the value $K$ is then a random variable that follows the **classical occupancy distribution** (see e.g., O'Neill 2020 for details). This distribution has probability mass function:

$$\mathbb{P}(K=k) = \frac{(m)_k \cdot S(n,k)}{m^n}
\quad \quad \quad \quad \quad
\text{for } 1 \leqslant k \leqslant \min(n,m),$$

where $(m)_k \equiv \prod_{i=0}^{k-1} (m-i)$ are the falling factorials and $S(n,k)$ are the Stirling numbers of the second kind.

You can find a great deal of information about this distribution in the linked paper, including the main moments of this distribution, asymptotic results when the parameters are large, and approximation and computation results. You may also be interested to note that the various probability functions for this distribution (mass function, cumulative distribution function, quantile function, random generation function) are available in `R`

using the functions `docc`

, `pocc`

, `qocc`

and `rocc`

in the `occupancy`

package. These functions can quickly compute the distribution for any computationally feasible value of $n$ and $m$.

## Best Answer

There are $7$ ways for one person to make a choice. Assuming they choose

uniformly,which means no person favors any choice over any other, each option therefore has a chance of $1/7.$ (This follows directly from the probability axioms, which assert the sum of all seven equal chances equals $1.$)When $n$ people

independentlymake choices, the very definition of independence means that any given array of choices has a chance of $1/7\times \cdots \times 1/7 = 1/7^n.$An array consisting of all distinct choices denotes a

permutationof those choices. There are $7$ permutations of one choice, $7\times (7-1)$ permutations of two choices (because the second cannot agree with the first), $7\times (7-1)\times (7-2)$ permutations of three choices (two possibilities are excluded from the first choice), and so on. The number of permutations of all $7$ options therefore is $7\times 6\times \cdots \times 1 = 7! = 5040.$Since all permutations of the choices are distinct, the probability axioms tell us to

addthe chances of all these permutations. This amounts to multiplying the common chance of $1/7^n$ by the number permutations, giving$$\frac{1}{7^7} \times 7! = \frac{5040}{823543} \approx 0.006119899$$

as stated in the question.