Is there a 1 in 20 or 1 in 400 chance of guessing the outcome of a d20 roll before it happens? My friends are in a bit of an argument over Dungeons & Dragons.
My player managed to guess the outcome of a D20 roll before it happened, and my friend said that his chance of guessing the number was 1 in 20. Another friend argues that his chance of guessing the roll is 1 in 400 because the probability of him randomly guessing a number and then rolling it were both 1 in 20 so the compound probability is 1 in 400. Which of these probabilities is a better characterization of our situation, and what were really his chances?
 A: Yes for any specific number $1,\ldots,20$ the probability that your friend selects that number and the dice rolls it is 1/400, but you must marginalize over all possible options:
If $X\sim \text{Unif}(1,\ldots,20)$, $Y\sim \text{Unif}(1,\ldots,20)$, Let $Z=X-Y$ then
$$
\begin{align*}
\text{P}(\text{predict roll}) &= \text{P}(Z=0)\\
&= \sum_{y=1}^{20} P(X=0+y)P(Y=y) &&\text{convolution formula for sums of random variables}\\
&= \sum_{y=1}^{20} \tfrac{1}{20}\tfrac{1}{20}\\
&= \tfrac{1}{20}
\end{align*}
$$
And by simulation
tmp <- data.frame(x=sample(1:20, size=100000, replace=TRUE ), y=sample(1:20, size=100000, replace=TRUE ))
> mean(tmp$x == tmp$y)
[1] 0.0497

A: Instead of a die roll, let's look at a coin flip. I guess whether the coin will land on heads or tails, and then you flip the coin.
There are four possible guess+outcome combinations:

*

*I guess heads, and the coin lands on heads.

*I guess heads, and the coin lands on tails.

*I guess tails, and the coin lands on heads.

*I guess tails, and the coin lands on tails.

Assuming that my guesses themselves are truly random—i.e. I am no more likely to guess any particular option than I am to guess any other*—then the probability that any particular guess+outcome combination will occur is (1/2)(1/2) = 1/4.
Now, any particular guess+outcome combination can be classified as either a "correct guess", meaning that the guess and the outcome match, or an "incorrect guess", meaning they do not match. The probability that a correct-guess combination will occur is computed by looking at each possible correct-guess combination, finding the probability that that particular combination will occur, and then summing those probabilities together. So in this case, the probability of a correct guess is (1/4)+(1/4) = 1/2.
This makes intuitive sense. We all know that our chances of guessing a coin flip are 50/50; if they were 25/75, we would never agree to a coin flip in the first place.
Your friend's die roll may be based on 1-in-20 odds instead of 1-in-2 odds, but the same logic applies. If your friend guesses randomly,* the probablility of any particular guess+outcome combination occurring is (1/20)(1/20) = 1/400. But since there are 20 possible correct-guess combinations (guess 1 + outcome 1, guess 2 + outcome 2, ..., guess 20 + outcome 20), the probability of a correct guess is (1/400)+(1/400)+...+(1/400) = 20/400 = 1/20.
*In real life, human beings do not guess randomly. When you ask people to pick a number between 1 and 10, they are more likely to pick 7 than 6 or 8. That complicates the math for determining the probability of any particular guess+outcome combination. But as long as the outcome (coin/die/whatever) remains random, the probability of a correct guess will not change, because the higher probability of certain guesses will be offset by the lower probability of the other guesses. fblundun's answer does a better job of describing this.
A: In more layman's terms, I would describe it like this:
Let's say the friend guesses 20--take that as a given. Now we roll the die, what's the chance that a d20 roll is 20? 1/20 = 5%.
Okay, now let's say the friend guesses 19. In this case, what's the chance that a d20 roll is 19? 1/20 = 5%.
What if the friend guesses 18? 1/20 = 5%.
Et cetera.
In every case, from guess = 1 up to guess = 20, the probability of the die roll equaling the guess is 1/20 = 5%. The guess doesn't matter at all (as long as it falls between 1 and 20, clearly a guess of 42 has a 0% chance of being correct). Whatever the guess, whether the process for generating the guess is random, bad human-approximation of random, fixed, or anything else, as long as the guess is between 1 and 20, the probability of the roll matching the guess is 1/20.
Mathematically, this is shown rigorously in @fblundun's answer - I'm trying to explain that math in an accessible way.
A: Let's simulate it!
set.seed(2021)
R <- 10000
d <- 20
guess <- sample(seq(1, d, 1), R, replace = T)
roll <- sample(seq(1, d, 1), R, replace = T)
length(which(guess == roll))/R

I get that about $1/20$ $(486/10000)$ times my guess match the roll. If you chop off the last digit of the seed and run the code with set.seed(202), I get exactly $5\%$. With next year's seed of 2022, I get $4.99\%$.
In more mathematical terms, this is the difference between the probability of rolling a number AND guessing that number (probably not what interests you) versus rolling a number GIVEN your guess. Assuming the roll and guess are independent...
$$
P(Roll = n) = 1/20\\
P(Guess = n) = 1/20\\
P(Roll = n \text{ AND } Guess = n) = 1/400\\
P(Roll = n \vert Guess = n) = \dfrac{P(Roll = n \text{ AND } Guess = n)}{P(Guess = n)} =  \dfrac{1/400}{1/20} = 1/20
$$
EDIT
If you don’t have equal probability of each number, the calculation can be modified. I’ll do the case where the human is not necessarily good at picking numbers with uniform probability of each number. Again, assume independence of the guess and the roll.
$$
P(Roll = n) = 1/20\\
P(Guess = n) = p\\
P(Roll = n \text{ AND } Guess = n) = p/20\\
P(Roll = n \vert Guess = n) = \dfrac{P(Roll = n \text{ AND } Guess = n)}{P(Guess = n)} =  \dfrac{p/20}{p} = 1/20
$$
If also the d20 is not fair:
$$
P(Roll = n) = p_1\\
P(Guess = n) = p_2\\
P(Roll = n \text{ AND } Guess = n) = p_1p_2\\
P(Roll = n \vert Guess = n) = \dfrac{P(Roll = n \text{ AND } Guess = n)}{P(Guess = n)} =  \dfrac{p_1p_2}{p_2} = p_1
$$
So it only depends on the probability of rolling a particular number.
A: Your another friend is arguing that:

*

*Guessing the roll; and

*Rolling the roll.

Are independent events. But that's not what you are measuring. You a measuring:

*

*Only the matching (of guest and roll has the same value).

There is one guest and 20 possible roll outcomes. So a chance of 1/20.
A: The probability of your friend correctly predicting the outcome of the roll was 1 in 20.
The probability of your friend correctly predicting that that specific number would be the outcome of the roll was 1 in 400.
Let's say the friend predicted it would be a 20. If you'd have been equally impressed if he'd predicted it would be a 4, then you're in the first situation (1/20). If you don't care about a correct prediction unless it was a 20, you're in the second situation (1/400).
Put another way, suppose you were watching your friend from behind a glass window, and you knew he was going to try to call the roll. If you said, "he will correctly predict the outcome of the roll" you'd have a 1 in 20 chance of being right. If you said, "he will correctly predict that he will roll a perfect 20" you'd have a 1 in 400 chance of being right.
A: What is the chance a D20 lands on 20? 5%.
What is the chance a D20 lands on 7? 5%.
What is the chance a D20 lands on [whatever number your friend named]? 5%.
No matter how you select a specific number from 1-20, a D20 has a 5% chance of matching it. Any particular number is always 5% likely, regardless of whether your friend chooses that number or not.
A: I don't think any of the existing answers explicitly state why the answer is 1 in 20 even if the friend is not equally likely to guess all 20 numbers (they aren't - humans are not good random number generators, and the friend might not even be trying to guess randomly).
For each possible roll $i$, let $p_i$ be the probability of your friend guessing $i$. We know that these probabilities must sum to 1:
$$\sum_{i=1}^{20}p_i = 1$$
Then the probability of the friend guessing correctly is:
$$
\sum_{i=1}^{20} P(\text{friend guesses } i)P(\text{roll }i) = \sum_{i=1}^{20}p_i \frac{1}{20} = \frac{1}{20}\sum_{i=1}^{20}p_i = \frac{1}{20}
$$
A: 
the probability of him randomly guessing a number and then rolling it
were both 1 in 20 so the compound probability is 1 in 400.

The probability of your friend guessing a number is not 1/20, the probability is 1. Unless there is a chance he would fail to guess anything or a chance he would guess something not on the D20.
So the formula for your friend guessing the correct outcome of the roll is:
1 * 1/20
or 1/20
Now, the odds of you guessing what your friend is going to guess and then that guess being correct, that would be 1/400. But that doesn't appear to be the situation.
A: Your friend is confusing the situation where both players roll the same specific number (which would give you 1/400) vs the situation you are in where they have to roll the same number but it could be any number (1/20). I suppose your confusion is that you have to roll the specific number your friend guessed but, which makes it seem like the first situation I described, however the difference is that your guess could have been any number.
