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?

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.
