title: shuffle algorithm with only random 0, 1
body: <p>I just read some interview question on the internet and made me curious at the solution.</p>
  
  <p>Problem is like this.</p>
  
  <p>Given a list of numbers and a rand(0,1) function, which returns a random integer between 0 and 1. Provide an algorithm to randomly sort the given list, based on the output of the rand() function, which should be called once for every number on the list.</p>
  
  <p>It seems asking to generate a random number with only 0 and 1 for shuffle.
  And I came up with this solution.</p>
  
  <pre><code>int random(int array_index, int array size)
  {
      return (array_index * 41 * (array_size + rand(0,1)) % array_size;
  }
  </code></pre>
  
  <p>But I feel this is not good enough since it depends on array_index.</p>
  
  <p>Anyone has better answer for this?</p>