2
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Why would you need to write an algorithm for something that's common sense? $\endgroup$ – MathematicsStudent1122 Aug 15 '16 at 11:30
  • $\begingroup$ @MathematicsStudent1122 Because other sources say its not true. Which indicates to me its not as obvious as it may initially seem. $\endgroup$ – sebjwallace Aug 15 '16 at 11:35
  • 2
    $\begingroup$ You talk about decimals and whole numbers... is 0.25 odd or even? $\endgroup$ – JP McCarthy Aug 15 '16 at 11:36
  • $\begingroup$ @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. $\endgroup$ – MathematicsStudent1122 Aug 15 '16 at 11:41
2
$\begingroup$

What you are testing is the distribution of numbers given by the particular pseudo-random number generator that your computer program is using. One of the most important properties of pseudo-random number generators is that each bit of the generated numbers appears to be random. This implies that the frequency of 0s and 1s should be equal (hence 50%), and hence the probability of odd or even numbers (being the last bit of the number) is the same.

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.