Why is generating 8 random bits uniform on (0, 255)? I am generating 8 random bits (either a 0 or a 1) and concatenating them together to form an 8-bit number.  A simple Python simulation yields a uniform distribution on the discrete set [0, 255].
I am trying to justify why this makes sense in my head.  If I compare this to flipping 8 coins, wouldn't the expected value be somewhere around 4 heads/4 tails?  So to me, it makes sense that my results should reflect a spike in the middle of the range.  In other words, why does a sequence of 8 zeroes or 8 ones seem to be equally as likely as a sequence of 4 and 4, or 5 and 3, etc.?  What am I missing here?
 A: All of the $2^8$ sequences have the same probability 1/$2^8$=1/256. It is a wrong to think that the sequences that have closer to an equal number of 0s and 1s is more likely as the question is interpreted.. It should be clear that we arrive at 1/256 because we assume independence from trial to trial. That is why we multiply the probabilities and the outcome of one trial has no influence on the next.
A: EXAMPLE with 3 bits (often an example is more illustrative)
I will write the natural numbers 0 through 7 as:


*

*A number in base 10

*A number in base 2 (i.e. a sequence of bits)

*A series of coin flips implied by the base 2 representation (1 denotes a flip of heads and 0 denotes a flip of tails).


$$\begin{array}
&\text{Base 10} & \text{Base 2 (with 3 bits)} & \text{Implied Coin Flip Series} &\text{Heads} & \text{Tails}\\
 0 & 000 & TTT & 0 & 3 \\
1 & 001 & TTH & 1 & 2\\
2 & 010 & THT & 1 & 2\\
3 & 011 & THH & 2 & 1\\
4 & 100 & HTT & 1 & 2\\
5 & 101 & HTH & 2 & 1\\
6 & 110 & HHT & 2 & 1\\
7 & 111 & HHH & 3 & 0
\end{array} $$
Choosing a natural number from 0 through 7 with equal probability is equivalent to choosing one of the coin flip series on the right with equal probability.
Hence if you choose a number from the uniform distribution over integers 0-7, you have a $\frac{1}{8}$ chance of choosing 3 heads, $\frac{3}{8}$ chance of choosing 2 heads, $\frac{3}{8}$ chance of choosing 1 head, and $\frac{1}{8}$ chance of choosing 0 heads.
A: TL;DR:
The sharp contrast between the bits and coins is that in the case of the coins, you're ignoring the order of the outcomes. HHHHTTTT is treated as the same as TTTTHHHH (both have 4 heads and 4 tails). But in bits, you care about the order (because you have to give "weights" to the bit positions in order to get 256 outcomes), so 11110000 is different from 00001111.

Longer explanation:
These concepts can be more precisely unified if we are a bit more formal in framing the problem. Consider an experiment to be a sequence of eight trials with dichotomous outcomes and probability of a "success" 0.5, and a "failure" 0.5, and the trials are independent. In general, I'll call this $k$ successes, $n$ total trials and $n-k$ failures and the probability of success is $p$.


*

*In the coin example, the outcome "$k$ heads, $n-k$ tails" ignores the ordering of the trials (4 heads is 4 heads no matter the order of occurrence), and this gives rise to your observation that 4 heads are more likely than 0 or 8 heads. Four heads are more common because there are many ways to make four heads (TTHHTTHH, or HHTTHHTT, etc.) than there are some other number (8 heads only has one sequence). The binomial theorem gives the number of ways to make these different configurations.

*By contrast, the order is important to bits because each place has an associated "weight" or "place value." One property of the binomial coefficient is that $2^n=\sum_{k=0}^n\binom{n}{k}$,  that is if we count up all the different ordered sequences, we get $2^8=256$. This directly connects the idea of how many different ways there are to make $k$ heads in $n$ binomial trials to the number of different byte sequences. 

*Additionally, we can show that the 256 outcomes are equally likely by the property of independence. Previous trials have no influence on the next trial, so the probability of a particular ordering is, in general, $p^k(1-p)^{n-k}$ (because joint probability of independent events is the product of their probabilities). Because the trials are fair, $P(\text{success})=P(\text{fail})=p=0.5$, this expression reduces to $P(\text{any ordering})=0.5^8=\frac{1}{256}$. Because all orderings have the same probability, we have a uniform distribution over these outcomes (which by binary encoding can be represented as integers in $[0,255]$).

*Finally, we can take this full circle back to the coin toss and binomial distribution. We know the occurrence of 0 heads doesn't have the same probability as 4 heads, and that this is because there are different ways to order the occurrences of 4 heads, and that the number of such orderings are given by the binomial theorem. So $P(\text{4 heads})$ must be weighted somehow, specifically it must be weighted by the binomial coefficient. So this gives us the PMF of the binomial distribution, $P(k \text{ successes})=\binom{n}{k}p^k(1-p)^{n-k}$. It might be surprising that this expression is a PMF, specifically because it's not immediately obvious that it sums to 1. To verify, we have to check that $\sum_{k=0}^n \binom{n}{k}p^k(1-p)^{n-k}=1$, however this is just a problem of binomial coefficients: $1=1^n=(p+1-p)^n=\sum_{k=0}^n \binom{n}{k}p^k(1-p)^{n-k}$.
A: Sycorax's answer is correct, but it seems like you're not entirely clear on why.
When you flip 8 coins or generate 8 random bits taking order into account, your result will be one of 256 equally likely possibilities. In your case, each of these 256 possible outcomes uniquely map to an integer, so you get a uniform distribution as your result.
If you don't take order into account, such as considering just how many heads or tails you got, there are only 9 possible outcomes (0 Heads/8 Tails - 8 Heads/0 Tails), and they're no longer equally likely. The reason for this is because out of the 256 possible results, there are 1 combination of flips that gives you 8 Heads/0 Tails (HHHHHHHH) and 8 combinations that give 7 Heads/1 Tails (a Tails in each of the 8 positions in the order), but 8C4 = 70 ways to have 4 Heads and 4 Tails. In the coin flipping case each of those 70 combinations maps to 4 Heads/4 Tails, but in the binary number problem each of those 70 outcomes maps to a unique integer.
A: The problem, restated, is: Why is the number of combinations of 8 random binary digits taken as 0 to 8 selected digits (e.g., the 1's) at a time different from the number of permutations of 8 random binary digits. In the context herein, random choice of 0's and 1's means that each digit is independent of any other, so that digits are uncorrelated and $p(0)=p(1)=\frac{1}{2}$; . 
The answer is: There are two different encodings; 1) lossless encoding of permutations and 2) lossy encoding of combinations. 
Ad 1) To lossless encode the numbers so that each sequence is unique we can view that number as being a binary integer $\sum_{i=1}^82^{i-1}{X_i}$, where ${X_i}$ are the left to right $i^{th}$ digits in the binary sequence of random 0's and 1's. What that does is make each permutation unique, as each random digit is then positional encoded. And the total number of permutations is then $2^8=256$. Then, coincidentally one can translate those binary digits into the base 10 numbers 0 to 255 without loss of uniqueness, or for that matter one can rewrite that number using any other lossless encoding (e.g. lossless compressed data, Hex, Octal). The question itself, however, is a binary one. Each permutation is then equally probable because there is then only one way each unique encoding sequence can be created, and we have assumed that the appearance of a 1 or a 0 is equally likely anywhere within that string, such that each permutation is equally probable. 
Ad 2) When the lossless encoding is abandoned by only considering combinations, we then have a lossy encoding in which outcomes are combined and information is lost. We are then viewing the number series, w.l.o.g. as the number of 1's; $\sum_{i=1}^82^{0}{X_i}$, which in turn reduces to $C(8,\sum_{i=1}^8{X_i})$, the number of combinations of 8 objects taken  $\sum_{i=1}^8{X_i}$ at at time, and for that different problem, the probability of exactly 4 1's is 70 ($C(8,4)$) times greater than obtaining 8 1's, because there are 70, equally likely permutations that can produce 4 1's.
Note: At the current time, the above answer is the only one containing an explicit computational comparison of the two encodings, and the only answer that even mentions the concept of encoding. It took a while to get it right, which is why this answer has been downvoted, historically. If there are any outstanding complaints, leave a comment.
Update: Since the last update, I am gratified to see that the concept of encoding has begun to catch on in the other answers. To show this explicitly for the current problem I have attached the number of permutations that are lossy encoded in each combination.
Note that the number of bytes of information lost during each combinatorial encoding is equivalent to the number of permutations for that combination minus one [$C(8,n)-1$, where $n$ is the number of 1's], i.e., for this problem, from $0$ to $69$ per combination, or $256-9=247$ overall.
A: 
why does a sequence of 8 zeroes or 8 ones seem to be equally as likely as a sequence of 4 and 4, or 5 and 3, etc

The aparent paradox can be summarized in two propositions, that might seem contradictory:


*

*The sequence $s_1: 00000000$  (eight zeroes) is equally probable as sequence $s_2: 01010101$ (four zeroes, four ones). (In general: all $2^8$ sequences have the same probability, regardless of how many zeroes/ones they have.)

*The event "$e_1$: the sequence had four zeroes" is more probable (indeed, $70$ times more probable) than the event "$e_2$: the sequence had eight zeroes".
These propositions are both true. Because the event $e_1$ includes many sequences.
A: I'd like to expand a little bit on the idea of order dependence vs. independence.
In the problem of calculating the expected number of heads from flipping 8 coins, we're summing the values from 8 identical distributions, each of which is the Bernoulli distribution $ B(1, 0.5) $ (in other words, a 50% chance of 0, a 50% chance of 1). The distribution of the sum is the binomial distribution $ B(8, 0.5) $, which has the familiar hump shape with most of the probability centered around 4.
In the problem of calculating the expected value of a byte made of 8 random bits, each bit has a different value that it contributes to the byte, so we're summing the values from 8 different distributions. The first is $ B(1, 0.5) $, the second is $ 2 B(1, 0.5) $, the third is $ 4 B(1, 0.5) $ , so on up to the eighth which is $ 128 B(1, 0.5) $. The distribution of this sum is understandably quite different from the first one. 
If you wanted to prove that this latter distribution is uniform, I think you could do it inductively — the distribution of the lowest bit is uniform with a range of 1 by assumption, so you would want to show that if the distribution of the lowest $ n $ bits is uniform with a range of $ 2^{n - 1} $ then the addition of the $ n+1 $st bit makes the distribution of the lowest $ n + 1 $ bits uniform with a range of $ 2^{n+1} - 1 $, achieving a proof for all positive $ n $. But the intuitive way is probably the exact opposite. If you start at the high bit, and choose values one at a time down to the low bit, each bit divides the space of possible outcomes exactly in half, and each half is chosen with equal probability, so by the time you get to the bottom, each individual value must have had the same probability to be chosen.
A: Each bit you choose is independent from each other bit. If you consider for the first bit there is a


*

*50% probability it will be  1 


and


*

*50% probability it will be 0. 


This also applies to the second bit, third bit and so on so that you end up with so for each possible combination of bits to make your byte you have $(\frac{1}{2})^8$ = $\frac{1}{256}$ chance of that unique 8 bit integer occurring.
A: If you do a binary search comparing each bit, then you need the same number of steps for each 8 bit number, from 0000 0000 to 1111 1111, they both have the length 8 bit. At each step in the binary search both sides have a 50/50 chance of occuring, so in the end, because every number has the same depth and the same probabilities, without any real choice, each number must have the same weight. Thus the distribution must be uniform, even when each individual bit is determined by coin flips. 
However, the digitsum of the numbers isn't uniform and would be equal in distribution to tossing 8 coins.
A: There is only one sequence with eight zeros. There are seventy sequences with four zeros and four ones.
Therefore, while 0 has a probability of 0.39%, and 15 [00001111] also has a probability of 0.39%, and 23 [00010111] has a probability of 0.39%, etc., if you add up all seventy of the 0.39% probabilities you get 27.3%, which is the probability of having four ones. The probability of each individual four-and-four result does not have to be any higher than 0.39% for this to work.
A: Consider dice
Think about rolling a couple of dice, a common example of non-uniform distribution. For the sake of the math, imagine the dice are numbered from 0 to 5 instead of the traditional 1 to 6. The reason the distribution is not uniform is that you are looking at the sum of the dice rolls, where multiple combinations can yield the same total like {5, 0}, {0, 5}, {4, 1}, etc. all generating 5. 
However, if you were to interpret the dice roll as a 2 digit random number in base 6, each possible combination of dice is unique. {5, 0} would be 50 (base 6) which would be 5*($6^1$) + 0*($6^0$) = 30 (base 10). {0, 5} would be 5 (base 6) which would be 5*($6^0$) = 5 (base 10). So you can see, there is a 1 to 1 mapping of possible dice rolls interpreted as numbers in base 6 versus a many to 1 mapping for the sum of the two dice each roll.
As both @Sycorax and @Blacksteel point out, this difference really boils down to the question of order.
