title: Using boost::random as the RNG for std::random_shuffle
body: <p>I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers.</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>void foo(std::vector&lt;unsigned&gt; &amp;vec, boost::mt19937 &amp;state)
  {
      struct bar {
          boost::mt19937 &amp;_state;
          unsigned operator()(unsigned i) {
              boost::uniform_int&lt;&gt; rng(0, i - 1);
              return rng(_state);
          }
          bar(boost::mt19937 &amp;state) : _state(state) {}
      } rand(state);
  
      std::random_shuffle(vec.begin(), vec.end(), rand);
  }
  </code></pre>
  
  <p>But i get a template error calling random_shuffle with rand. However this works:</p>
  
  <pre><code>unsigned bar(unsigned i)
  {
      boost::mt19937 no_state;
      boost::uniform_int&lt;&gt; rng(0, i - 1);
      return rng(no_state);
  }
  void foo(std::vector&lt;unsigned&gt; &amp;vec, boost::mt19937 &amp;state)
  {
      std::random_shuffle(vec.begin(), vec.end(), bar);
  }
  </code></pre>
  
  <p>Probably because it is an actual function call. But obviously this doesn't keep the state from the original mersenne twister. What gives? Is there any way to do what I'm trying to do without global variables?</p>