title: boost::random generate the same number every time
body: <p>main .cpp</p>
  
  <pre><code>#include        "stdafx.h"
  #include        "random_generator.h"
  
  
          int
  main ( int argc, char *argv[] )
  {
          cout.setf(ios::fixed);
          base_generator_type base_generator;
          int max = pow(10, 2);
          distribution_type dist(1, max);
  
          boost::variate_generator&lt;base_generator_type&amp;,
  distribution_type &gt; uni(base_generator, dist);
          for ( int i=0; i&lt;10; i++ ) {
                  //cout &lt;&lt; random_number(2) &lt;&lt; endl;
                  cout &lt;&lt; uni() &lt;&lt; endl;
          }
  
          return EXIT_SUCCESS;
  
  }                               /* ----------  end of function main  ---------- */
  </code></pre>
  
  <p>random_gemerator.h</p>
  
  <pre><code>#include        "stdafx.h"
  
  #include        &lt;boost/random.hpp&gt;
  #include        &lt;boost/generator_iterator.hpp&gt;
  
  typedef boost::mt19937 base_generator_type;
  typedef boost::lagged_fibonacci19937 fibo_generator_type;
  typedef boost::uniform_int&lt;&gt; distribution_type;
  typedef boost::variate_generator&lt;fibo_generator_type&amp;,
  distribution_type&gt; gen_type;
  
          int
  random_number ( int bits )
  {
          fibo_generator_type fibo_generator;
          int max = pow(10, bits);
          distribution_type dist(1, max);
  
          gen_type uni(fibo_generator, dist);
          return uni();
  
  }               /* -----  end of function random_number  ----- */
  </code></pre>
  
  <p>stdafx.h</p>
  
  <pre><code> #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  </code></pre>
  
  <p>every time I run it, it all generate the same number sequence</p>
  
  <p>like 77, 33,5, 22 , ...</p>
  
  <p>how to use boost:random correctly? </p>
  
  <hr>
  
  <p>that is it. but maybe have a little problem, like the following:</p>
  
  <p>it seems sound</p>
  
  <pre><code>get_seed(); for (;;) {cout &lt;&lt; generate_random() &lt;&lt; endl; } // is ok 
  </code></pre>
  
  <p>it genereate the same random number</p>
  
  <pre><code>int get_random() {get_seed();return generate_random();} for (;;) {cout &lt;&lt; get_random() &lt;&lt;endl;}  // output the same random number yet
  </code></pre>