summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2014-10-07 10:09:44 +0300
committerTor Lillqvist <tml@collabora.com>2014-10-07 10:13:36 +0300
commit4bb67e666b2ca36a5caa5c3f22d0f1e802db527e (patch)
tree054fe4c36039e7329ea04f7590421944eb34b21f /comphelper
parent020f46d17065b8b00365eab7a809ce980ebfb59a (diff)
Handle incorrect usage of uniform_real_distribution()
uniform_real_distribution(a,b) should be called with a < b, otherwise the result is undefined. Currently, when called with both zero, it gets stuck in a loop. Not sure if a blunt assert() would be the right thing here, so I just return a if a >= b. Change-Id: I769688c7192bd02bad24ad597948984db56dd4fc
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/random.cxx3
1 files changed, 3 insertions, 0 deletions
diff --git a/comphelper/source/misc/random.cxx b/comphelper/source/misc/random.cxx
index c695ed12a2f7..9071765585fd 100644
--- a/comphelper/source/misc/random.cxx
+++ b/comphelper/source/misc/random.cxx
@@ -80,6 +80,9 @@ size_t uniform_int_distribution(size_t a, size_t b)
// uniform size_t [a,b) distribution
double uniform_real_distribution(double a, double b)
{
+ // Probably too rude to just assert(a < b), so instead...
+ if (a >= b)
+ return a;
boost::random::uniform_real_distribution<double> dist(a, b);
return dist(theRandomNumberGenerator::get().global_rng);
}