At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
This is not a computer science question. I recommend you ask it in the Mathematics section.
Not the answer you are looking for? Search for more explanations.
If you do a little number theory, you will realize that the sum of two even numbers and two odd numbers is always even. Therefore, you are looking at all the possibilities of obtaining two numbers of the same parity. The sample space of an 8-sided die rolled twice has a size of 64 outcomes. However, we are only interested in a specific subset of this sample space, namely, of numbers with the same parity.
On your first roll, you can get anything, but you have two options: either an odd number or an even number. On your second roll, you are only interested in a number whose parity matches that of the first number. In the case of an 8-sided die, you will have 4 options. Hence, it is easy to see that you will have a sample space of 16 favorable outcomes.
Oh, yes, I forgot to add the even parity. Hence, 16+16.