title: How can I determine the statistical randomness of a binary string?
body: <p>How can I determine the statistical randomness of a binary string?</p>
  
  <p>Ergo, how can I code my own test, and return a single value that corresponds to the statistical randomness, a value between 0 and 1.0 (0 being not random, 1.0 being random)?</p>
  
  <p>The test would need to work on binary strings of any size.</p>
  
  <p>When you do it with pen and paper, you might explore strings like this:<br>
  &nbsp;&nbsp;0 (arbitrary randomness, the only other choice is 1)<br>
  &nbsp;&nbsp;00 (not random, its a repeat and matches the size)<br>
  &nbsp;&nbsp;01 (better, two different values)<br>
  &nbsp;&nbsp;010 (less random, palindrome)<br>
  &nbsp;&nbsp;011 (less random, more 1's, still acceptable)<br>
  &nbsp;&nbsp;0101 (less random, pattern)<br>
  &nbsp;&nbsp;0100 (better, less ones, but any other distribution causes patterns)<br></p>
  
  <p><b>Case examples:</b></p>
  
  <p>Size: 1, Possibilities: 2<br>
  &nbsp;&nbsp;0: 1.0 (random)<br>
  &nbsp;&nbsp;1: 1.0 (random)<br></p>
  
  <p>Size: 2, P:4<br>
  &nbsp;&nbsp;00: ?<br>
  &nbsp;&nbsp;01: 1.0 (random)<br>
  &nbsp;&nbsp;10: 1.0 (random)<br>
  &nbsp;&nbsp;11: ?<br></p>
  
  <p>S:3, P:8<br>
  &nbsp;&nbsp;000: ? non-random<br>
  &nbsp;&nbsp;001: 1.0 (random)<br>
  &nbsp;&nbsp;010: ? less random<br>
  &nbsp;&nbsp;011: 1.0 (random)<br>
  &nbsp;&nbsp;100: 1.0 (random)<br>
  &nbsp;&nbsp;101: ? less random<br>
  &nbsp;&nbsp;110  1.0 (random)<br>
  &nbsp;&nbsp;111: ? non-random<br></p>
  
  <p>And so on.<br><br></p>
  
  <p>I feel that this may play a lot into breaking the string into all possible substrings and comparing frequencies, but it seems like this sort of groundwork should already have been done in the early days of computer science.</p>