title: Run length control of 2 on a binary variable with python list
body: <p>I want to pseudo-randomly create a list with 48 entries -- 24 zeros and 24 ones -- where neither zero nor one repeats more than twice in a row. For example:</p>
  
  <pre><code>[1,1,0,1,0,0,1,1,0,1,0,...]
  
  import random
  l = list()
  for i in range(48):
      if len(l) &lt; 2:
          l.append(random.choice([0,1]))
      else:
          if l[i-1] == l[i-2]:
              if l[i-1] == 0:
                  l.append(1)
              else:
                  l.append(0)
          else:
              l.append(random.choice([0,1]))
  </code></pre>
  
  <p>I have the above code, but it sometimes returns an uneven count of 1s or 0s. All possible solutions should have the same chance of coming up. </p>