http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48114
Summary: <random> binomial_distribution incorrect for p > .5 Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: a...@althenia.net Created attachment 23651 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23651 Probability table for binomial_distribution. The attached program samples binomial_distribution(10, .75) and calculates the correct probabilities of each outcome. The output shows that the probabilities are reversed. With p > .5 the distribution should be biased toward higher values. sample correct p_0 0.056 0.000 p_1 0.185 0.000 p_2 0.283 0.000 p_3 0.252 0.003 p_4 0.147 0.016 p_5 0.058 0.058 p_6 0.016 0.146 p_7 0.003 0.250 p_8 0.000 0.282 p_9 0.000 0.188 p_10 0.000 0.056 The problem is here, __param.p() is a double. --- include/c++/bits/random.tcc +++ include/c++/bits/random.tcc @@ -1434,7 +1434,7 @@ { result_type __ret; const _IntType __t = __param.t(); - const _IntType __p = __param.p(); + const double __p = __param.p(); const double __p12 = __p <= 0.5 ? __p : 1.0 - __p; __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng);