Subject: [Boost-bugs] [Boost C++ Libraries] #7020: uniform_01 improvement
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-06-23 01:23:00
#7020: uniform_01 improvement
--------------------------------------------+-------------------------------
Reporter: agribov_no_s_p_a_m@⦠| Owner: no-maintainer
Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
Version: Boost 1.49.0 | Severity: Optimization
Keywords: uniform_01 |
--------------------------------------------+-------------------------------
The current code to simulate uniform random number in interval [0;1]
contains verification to skip 1.
if (result < result_type(1))
return result;
It means that random generator can generate 0 but not 1. This is used in
some other code, for example, generate Exponential random number:
return -result_type(1) /
_lambda * log(result_type(1)-uniform_01<RealType>()(eng));
Meaning (1 - random number) will never be 0.
If eng() returns integer number, then, with some limitations for
result_type and generated range of random numbers (result_type has to be
double for generated 32 bit random numbers):
result_type factor = result_type(1) /
(result_type((eng.max)()-(eng.min)()) + result_type(1));
return (result_type(eng() - (eng.min)()) + result_type(0.5)) * factor;
In this case, the result will never contain 0 or 1 and will be unbiased.
No more checking for 0 or 1 is necessary.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7020> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC