re PR libstdc++/33815 (tr1::uniform_int isn't uniform)
2007-10-19 Paolo Carlini <pcarlini@suse.de> PR libstdc++/33815 * include/tr1_impl/random (uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type, result_type, true_type)): Avoid the modulo (which uses the low-order bits). From-SVN: r129493
This commit is contained in:
parent
3c167a8bbb
commit
23e8722aed
|
@ -1,3 +1,11 @@
|
||||||
|
2007-10-19 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
PR libstdc++/33815
|
||||||
|
* include/tr1_impl/random
|
||||||
|
(uniform_int<>::_M_call(_UniformRandomNumberGenerator&, result_type,
|
||||||
|
result_type, true_type)): Avoid the modulo (which uses the low-order
|
||||||
|
bits).
|
||||||
|
|
||||||
2007-10-19 Paolo Carlini <pcarlini@suse.de>
|
2007-10-19 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
* include/bits/stl_algobase.h (struct __cm_assign,
|
* include/bits/stl_algobase.h (struct __cm_assign,
|
||||||
|
|
|
@ -1605,9 +1605,13 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
|
||||||
_M_call(_UniformRandomNumberGenerator& __urng,
|
_M_call(_UniformRandomNumberGenerator& __urng,
|
||||||
result_type __min, result_type __max, true_type)
|
result_type __min, result_type __max, true_type)
|
||||||
{
|
{
|
||||||
|
// XXX Must be fixed to also work when __urng.max() - __urng.min()
|
||||||
|
// is smaller than __max - __min.
|
||||||
typedef typename __gnu_cxx::__add_unsigned<typename
|
typedef typename __gnu_cxx::__add_unsigned<typename
|
||||||
_UniformRandomNumberGenerator::result_type>::__type __utype;
|
_UniformRandomNumberGenerator::result_type>::__type __utype;
|
||||||
return result_type(__utype(__urng()) % (__max - __min + 1)) + __min;
|
return result_type((__max - __min + 1.0L) * __utype(__urng())
|
||||||
|
/ (__utype(__urng.max())
|
||||||
|
- __utype(__urng.min()) + 1.0L)) + __min;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _UniformRandomNumberGenerator>
|
template<typename _UniformRandomNumberGenerator>
|
||||||
|
|
Loading…
Reference in New Issue