I think you have to use the time as argument for the generator<br>�<font size="1"><span style="font-family: courier new,monospace;">mt19937 gen(time(0));</span></font><br><br><div class="gmail_quote">2011/1/24 Zolt�n Lengyel <span dir="ltr">&lt;<a href="mailto:katzlengyel@gmail.com">katzlengyel@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello,<br>I am trying to make a simple program that can generate random integers in range, using boost::uniform_int.<br>
<br><a href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/tutorial.html#boost_random.tutorial.generating_integers_in_a_range" target="_blank">http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/tutorial.html#boost_random.tutorial.generating_integers_in_a_range</a><br>


This tutorial tells:<br>&quot;We use <code><a href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost/mt19937.html" title="Type definition mt19937" target="_blank">mt19937</a></code> with the default
        seed as a source of randomness. The numbers produced will be the same every
        time the program is run. One common method to change this is to seed with
        the current time (<code><span>std</span><span>::</span><span>time</span><span>(</span><span>0</span><span>)</span></code> defined in ctime).&quot;<br>
<br>I have trouble getting this common method compile and work. Here&#39;s a
 tiny program that works, with the same seed at every run (like what the
 tutorial does), I have commented out my desperate tries to make the 
seed change.<br>
<br><br><font size="1"><span style="font-family: courier new,monospace;">#include &quot;uniform_int.hpp&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;boost/random/variate_generator.hpp&quot;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">#include &quot;boost/random/mersenne_twister.hpp&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &lt;time.h&gt;</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &lt;iostream&gt;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using namespace std;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">using namespace boost;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mt19937 gen;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">// time_t gen = time(0);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">int roll_die()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">��� uniform_int&lt;&gt; dist(1, 6);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">��� variate_generator&lt;mt19937&amp;, uniform_int&lt;&gt; &gt; die(gen, dist);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">��� //boost::variate_generator&lt;time_t, boost::uniform_int&lt;&gt; &gt; die(gen, dist);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">��� return die();</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main()</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">��� for (int i = 0; i &lt; 5; i++)</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">��� ��� cout &lt;&lt; roll_die() &lt;&lt; endl;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">��� return 0;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">}</span></font><br><br>So, I would be glad, if someone could fix this for me, to have a different seed (depending on system time) at each start.<br>Thanks!
<br>_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org">Boost-users@lists.boost.org</a><br>
<a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br></blockquote></div><br>