title: generate a random int given a random bit function
body: <p>Suppose  you're given a <code>int randBit()</code> function which returns, uniformly distributed, 0 or 1.</p>
  
  <p>Write a randNumber(int max) function.</p>
  
  <p>This is my implementation, but I can't prove/disprove that it's right.</p>
  
  <pre><code>    // max number of bits
      int i = (int)Math.floor(Math.log(max) / Math.log(2)) + 1;
  
      int ret = randBit();
      while (i-- &gt; 0) {
          ret = ret &lt;&lt; 1 | randBit();
      }
  
      return ret;
  </code></pre>
  
  <p>The basic idea I had is that </p>
  
  <ul>
  <li>find the number of bits present in the number</li>
  <li>then generate the number by continuously concatenating the LSB until the bitlength is met</li>
  </ul>