How do you measure the likelihood of having a run? I have some data that has runs of 0s with some 1s thrown in. For example:  
000000000100000000010000000000000000000111111100000000

However, the 1s are much more sparse. 
I want to calculate a measure of how "runny" the data is.  What I mean by this is I want to have a low value if my data only has single 1s interspersed with 0s. But if there are lots of runs of 1s or long runs of 1s I want a high value.
What is a good way to measure this?
 A: You can use the runs test:
Let N be the number of observations, with $N_+$ and $N_-$ the 1's and 0's. Then, if the null is true, the number of runs (of any length) should be normally distributed with :
$\mu = \frac{N_+N_-}{N}+ \frac{1}{2}$
and
$\sigma^2 = \frac{(\mu - 1)(\mu-2)}{N-1}$
you can then test this with standard tables or functions. 
A: While I think @PeterFlom's answer is better than you realize, there's a test for the number of runs of one kind; the number of runs of "1"s has a hypergeometric distribution.
If $n_1$ is the number of 1's and $n_0$ is the number of 0's and $n = n_0+n_1$, and $G$ is the number of runs of 1s, then assuming that $n_1$ is at least 1:
$G$ ranges between $1$ and $\min(n_1, n_0+1)$  (in your case, that upper bound will probably always be $n_1$).
$E(G)=\frac{n_1(n_0+1)}{n}$
$Var(G)=\frac{n_1 n_0(n_1-1)(n_0+1)}{n^2(n-1)}$
$P(G=g) = \frac{\binom{n_1-1}{g-1}\binom{n_0+1}{g}}{\binom{n_1+n_0}{n_1}}$
You could construct various measures of 'lumpiness' of 1's from those measures.
As I point out in my comment on Peter Flom's answer, this is closely related to the more usual runs test he discusses.
e.g. 1: If you take an index like this: $R = \frac{G-E(G)}{n_1-E(G)}$ ($R$ for 'runs index', not anything to do with correlation) then $R$ will be a number that takes the value 1 when the number of runs is at a maximum (one run for every '1'), which takes the value 0 when the number of runs reflects 'random' lumpiness, and is negative when the 1's are lumpier than random. If there's exactly one run of '1's, it attains its minimum value, but that value can't quite reach -1.
A: Why not use a simple counting approach for your measure? Start your count at zero. For every isolated "1" you add 1 to your count. For every instance of "11" you add two to the count. A triple "111" will add four to the count, and so on. If you don't like this weighting scheme, then create one more in line with how you want to balance a lot of isolated ones versus a longer streak. 
If you need to compare data streams of different lengths, then you will need to make an adjustment for the length of each data pattern. 
