Given the digits of a passcode, what is the probability of getting 4 in their correct location?

Say you have a passcode $$135790$$ and a burglar knows exactly what digits it is made up of and that there no duplicates, but not the correct ordering.

How do you calculate the probability that he gets exactly $$4$$ of the digits in their correct location?

I was initially thinking it would be like a binomial distribution, but because you cannot re-use a number each choice is not independent and the number of possible digits decreases each time you pick a digit.

Count the ways to select four from the six to put in their correct place, and put the other two in the incorrect place. That is the count of favoured outcomes.

The count for total outcomes is that of all the ways to arrange the six digits.

Divide and calculate.

• So that makes me think $6C4*(1/6)^4*(5/6)^2$? – Tiernan Watson Apr 24 at 2:09
• No. It is not a binomial distribution. The success rates of the tumblers are not independent because repeatition is disallowed. @TiemanWatson – Graham Kemp Apr 24 at 2:15
• I can see there are 15 ways to select 4 from the 6. What you've said just makes me think of writing down all 15 of those, which is what I can do and I understand how to get the right answer from that. Was that the method you were alluding to? I just feel like there should be a quicker way, and I'm still not seeing it, unless there isn't. – Tiernan Watson Apr 24 at 2:20
• There are indeed $15$ ways to arrange the digits so that exactly four are correct, or $6!\div (4!2!)$. There are, in total, $6!$ ways to arrange the six digits. So... – Graham Kemp Apr 24 at 2:31
• I basically spelt it out to myself in the last comment haha. Thanks. – Tiernan Watson Apr 24 at 2:36

It would be derangement. Select 4 out of n and there is only one way for them . So $$C_4^n$$ Now rest $$n-4$$ are such that no one is in it's correct position. Using derangement formula: $$(n-4)!(1-\frac 1 {1!} + \frac 1 {2!} - \frac 1 {3!} + ..... + (-1)^{n-4} \frac 1 {(n-4)!} )$$ The total required ways can be found by multiplying these two. And the total ways are obviously,$$n!$$. Then we can find the probability.