# Are half of all numbers even? [duplicate]

I've just written a quick algorithm that tests if a random number (decimal or whole) between -million and +million is divisible by 2. It iterated a million numbers. The sum of even numbers was ~50% every time.

I've read mixed opinions about if 'half of all numbers are even/odd'. My test shows it is true. But I feel I maybe missing something. Is there a mathematical explanation behind why this seems to be true?

## marked as duplicate by user91500, Watson, Namaste, user223391, DidAug 15 '16 at 12:38

• @sebjwallace The problems occur when considering infinite subsets of $\mathbb{Z}$ because "half" an infinite makes no sense. For finite subsets of the form $\{-n, -n+1...., n-1, n\}$ it is fairly clear that half of the numbers are odd and half are even and so we have no problem. – MathematicsStudent1122 Aug 15 '16 at 11:41
From a mathematical point of view the things are not so easy as they appear. If your numbers have a range, for example $0$...$(2^{64}-1)$, then there is a unique uniform distribution of probability (one where each number has the same probability) and since there are an equal number of odd and even numbers in this interval, they have equal probability. If you instead pretend to consider a uniform distribution on the whole set of natural or whole numbers, this is not possible to have. Hence the concept of "probability of a number being even" is not uniquely understood. Possible probability measures usually are higher for small numbers and lower for high numbers. If, for example, $0$ is the number with higher probability, and the probability decreases with magnitude, than the even number would have slightly higher probability than odd numbers.