Number of expected pairs in a random shuffle Suppose there are 34 poeople standing in a row in random order, among them 18 are male and 16 are female. If two people adjacent to each other belong to different genders, we consider them to be a couple, how many couples are we expected to see on average?
 A: Someone much wiser then me will post a theoretical and exact solution. Meanwhile my attempt at a simulation:
once <- function(){
    row <- sample(c(rep("m", 18), rep("f",16)))
    count <- 0
    for(i in 1:33){
        if(row[i]!=row[i+1]) 
        count <- count + 1
    }
    return(count)
}


run <- replicate(1e5, once())
plot(table(run))


> table(run)
run
    6     7     8     9    10    11    12    13    14    15    16    17    18    19    20    21    22    23    24    25    26    27    28    29 
    5    25    79   280   663  1643  3070  5555  8057 11169 12883 14309 12818 11020  7682  5279  2931  1535   635   261    78    17     4     2

> summary(run)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   6.00   15.00   17.00   16.96   19.00   29.00 

A: First, we find the probability that two adjacent individuals are of different genders.  Those two people are equally likely to be   any of the ${34 \choose 2}$ pairs of people, of which $18 \times 16$ are male-female pairs, so this probability is $(18 \times 16)/{34 \choose 2}$.
The total number of pairs is $X_1 + X_2 + \cdots + X_{33}$ where $X_i$ is an indicator random variable that is 1 if person $i$ and person $i+1$ are of opposite genders and 0 otherwise.  Its expectation is $E(X_1) + \cdots + E(X_{33})$, but all these variables have the same expectation, the probability we found above. So the answer is
$$ 33 \times {18 \times 16 \over {34 \choose 2}} = {33 \times 18 \times 16 \over (34 \times 33)/2} = {18 \times 16 \over 17} = {17^2 - 1 \over 17}  = 17 - {1 \over 17} \approx 16.94.$$
This agrees with Bernhard's simulation.
More generally, if you have $m$ males and $f$ females and the same problem you get
$$ (m+f-1) {mf \over {m+f \choose 2}} = {(m+f-1) mf \over (m+f)(m+f-1)/2} = {2mf \over m+f}$$
which can  also be checked by simulation.
