Boost C++ Libraries: Ticket #10921: Seeding boost::random::mt19937 from a pair of iterators throws an exception https://svn.boost.org/trac10/ticket/10921 <p> The problem is that when seeding <code>boost::random::mt19937</code> from a pair of iterators <code>std::invalid_argument("Not enough elements in call to seed")</code> exception is thrown. </p> <p> An isolated test case looks like this: </p> <pre class="wiki">#include &lt;boost/array.hpp&gt; #include &lt;boost/random.hpp&gt; //typedef boost::random::rand48 generator_t; typedef boost::random::mt19937 generator_t; int main() { typedef boost::array&lt;int, 3&gt; seed_range_t; seed_range_t seed = {1, 2, 3}; boost::random::seed_seq seed2(seed.begin(), seed.end()); generator_t generator1(seed2); // works fine seed_range_t::iterator begin = seed.begin(); generator_t generator2(begin, seed.end()); // throws std::invalid_argument("Not enough elements in call to seed") } </pre><p> The documentation of the relevant constructor [1] does not help too much. </p> <p> Please note that using the same input sequence through <code>boost::random::seed_seq</code> works fine. Moreover, the same input sequence passed directly to the constructor of <code>boost::random::rand48</code> generator also produces no exceptions. </p> <p> I'm not sure if <code>mersenne_twister_engine</code> needs larger input or the implementation is broken. Please advice. </p> <p> [1] <a href="http://www.boost.org/doc/libs/1_57_0/doc/html/boost/random/mersenne_twister_engine.html#idp93974544-bb">http://www.boost.org/doc/libs/1_57_0/doc/html/boost/random/mersenne_twister_engine.html#idp93974544-bb</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10921 Trac 1.4.3 Steven Watanabe Thu, 26 Feb 2015 00:17:34 GMT <link>https://svn.boost.org/trac10/ticket/10921#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10921#comment:1</guid> <description> <p> This behavior is expected. The iterator constructors require you to provide a range sufficiently large to fill the entire state of the generator. Seeding with a pair of iterators is provided for backwards compatibility. New code should use seed_seq (or std::seed_seq). </p> </description> <category>Ticket</category> </item> <item> <author>Adam Romanek <romanek.adam@…></author> <pubDate>Thu, 26 Feb 2015 07:24:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10921#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10921#comment:2</guid> <description> <p> So this is a shortcoming of the documentation. Thanks for the info. </p> </description> <category>Ticket</category> </item> </channel> </rss>