Boost C++ Libraries: Ticket #6022: WeightType is misleading in boost::random::discrete_distribution https://svn.boost.org/trac10/ticket/6022 <p> The class template <code>boost::random::discrete_distribution</code> is parameterized by types <code>IntType</code> (defaulting to <code>int</code>) and <code>WeightType</code> (defaulting to <code>double</code>). Could you please update the documentation to clarify that <code>WeightType</code> must be a floating-point type? Alternatively, if the implementation could be changed to allow integer <code>WeightType</code>s that would be even better! (But I imagine that could be a lot of work.) </p> <p> A bit more background: </p> <p> The documentation doesn't give any constraints on <code>WeightType</code>, and in fact the documentation for one of the constructors gives as an example </p> <pre class="wiki">discrete_distribution&lt;&gt; dist{1, 4, 5}; </pre><p> which indicates that weights don't have to sum to 1, and hints at the possibility of using an integer <code>WeightType</code> -- which would often be convenient and efficient. However, the following snippet fails compilation: </p> <pre class="wiki">#include &lt;boost/random.hpp&gt; void f() { int w[] = {1, 4, 5}; boost::random::discrete_distribution&lt;int, int&gt; dist(w, w + 3); } </pre><p> Changing the <code>&lt;int, int&gt;</code> to <code>&lt;int, double&gt;</code> or just <code>&lt;int&gt;</code> enables compilation. (Also, looking at the Boost implementation, I see a call to an internal <code>normalize()</code> method that divides all weights by their sum, so it looks like support for integer <code>WeightType</code>s was never intended.) </p> <p> Thanks, Tim </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6022 Trac 1.4.3 Steven Watanabe Fri, 14 Oct 2011 15:05:58 GMT <link>https://svn.boost.org/trac10/ticket/6022#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6022#comment:1</guid> <description> <p> I intended to support integer weight types, but it requires a separate implementation and I haven't gotten around to it yet. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 13 Mar 2014 20:15:13 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6022#comment:2 https://svn.boost.org/trac10/ticket/6022#comment:2 <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> Fixed in <a class="ext-link" href="http://github.com/boostorg/random/commit/dbb7b3cfaa938a38ed012c924d5ceeafb3357691"><span class="icon">​</span>http://github.com/boostorg/random/commit/dbb7b3cfaa938a38ed012c924d5ceeafb3357691</a>. </p> Ticket