Boost C++ Libraries: Ticket #3516: lagged fibonacci cannot be seeded with a value 0 - fails with assertion error https://svn.boost.org/trac10/ticket/3516 <p> When using the lagged_fibonacci607 and attempting to seed, the attached test program will either stop with an assertion error at line 57 of boost/random/linear_congruential.hpp, or if -DNDEBUG is used during compilation to disable assertions, the returned values are not in range. </p> <p> Seeding with a zero value should not cause such problems. </p> <pre class="wiki">#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;boost/random/lagged_fibonacci.hpp&gt; using namespace std; boost::lagged_fibonacci607 lfrand; inline int fastrand (int range) { return ((int) range * lfrand()); } main (int argc, char **argv) { unsigned int seed; if (argc &lt; 2) { printf ("Usage lftest &lt;seed&gt;\n"); exit (1); } sscanf (argv[1], "%d", &amp;seed); printf ("using seed value %d\n", seed); lfrand.seed (seed); for (int n = 0; n &lt; 1000000; n++) { int x = fastrand (10); if (x &lt; 0 || x &gt; 9) printf ("out of range random number[%d] = %d\n", n, x); } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3516 Trac 1.4.3 Steven Watanabe Mon, 12 Oct 2009 19:04:47 GMT <link>https://svn.boost.org/trac10/ticket/3516#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3516#comment:1</guid> <description> <p> This is a limitation of the seeding algorithm. lagged_fibonacci::seed is documented to use minstd_rand0 which cannot be seeded with 0. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 16 Oct 2009 20:04:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3516#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3516#comment:2</guid> <description> <p> I think that the correct way to fix this is to change the wrap-around algorithm in linear_congruential so that it can handle zero. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Sat, 14 Nov 2009 21:07:33 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3516#comment:3 https://svn.boost.org/trac10/ticket/3516#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/57663" title="Allow arbitrary values to be used as seeds for linear_congruential, ...">[57663]</a>) Allow arbitrary values to be used as seeds for linear_congruential, linear_feedback_shift, and any generators that depend on them. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3516" title="#3516: Bugs: lagged fibonacci cannot be seeded with a value 0 - fails with ... (closed: fixed)">#3516</a> </p> Ticket