From 8f436d3de7e99268a8862664d2cb2574231c3b18 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 3 Oct 2014 17:12:23 +0100 Subject: use comphelper::rng::uniform_*_distribution everywhere and automatically seed from time on first use coverity#1242393 Don't call rand coverity#1242404 Don't call rand coverity#1242410 Don't call rand and additionally allow 0xFF as a value coverity#1242409 Don't call rand coverity#1242399 Don't call rand coverity#1242372 Don't call rand coverity#1242377 Don't call rand coverity#1242378 Don't call rand coverity#1242379 Don't call rand coverity#1242382 Don't call rand coverity#1242383 Don't call rand coverity#1242402 Don't call rand coverity#1242397 Don't call rand coverity#1242390 Don't call rand coverity#1242389 Don't call rand coverity#1242388 Don't call rand coverity#1242386 Don't call rand coverity#1242384 Don't call rand coverity#1242394 Don't call rand Change-Id: I241feab9cb370e091fd6ccaba2af941eb95bc7cf --- drawinglayer/source/primitive2d/polygonprimitive2d.cxx | 16 +++++++++++----- drawinglayer/source/texture/texture.cxx | 9 ++++----- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'drawinglayer') diff --git a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx index 79a5e9e10c54..4a2944be5bb0 100644 --- a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx @@ -25,9 +25,9 @@ #include #include #include +#include #include - - +#include using namespace com::sun::star; @@ -212,10 +212,16 @@ namespace drawinglayer } // end of namespace primitive2d } // end of namespace drawinglayer - - namespace drawinglayer { + namespace tools + { + double getRandomColorRange() + { + return comphelper::rng::uniform_real_distribution(0.0, boost::math::nextafter(1.0, DBL_MAX)); + } + } + namespace primitive2d { Primitive2DSequence PolygonStrokePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const @@ -271,7 +277,7 @@ namespace drawinglayer const basegfx::B2DPolyPolygon aNewPolyPolygon(aAreaPolyPolygon.getB2DPolygon(b)); static bool bTestByUsingRandomColor(false); const basegfx::BColor aColor(bTestByUsingRandomColor - ? basegfx::BColor(rand() / 32767.0, rand() / 32767.0, rand() / 32767.0) + ? basegfx::BColor(tools::getRandomColorRange(), tools::getRandomColorRange(), tools::getRandomColorRange()) : getLineAttribute().getColor()); const Primitive2DReference xRef(new PolyPolygonColorPrimitive2D(aNewPolyPolygon, aColor)); aRetval[b] = xRef; diff --git a/drawinglayer/source/texture/texture.cxx b/drawinglayer/source/texture/texture.cxx index e1f8f92a3a5a..89953e624395 100644 --- a/drawinglayer/source/texture/texture.cxx +++ b/drawinglayer/source/texture/texture.cxx @@ -18,12 +18,11 @@ */ #include +#include #include #include #include - - namespace drawinglayer { namespace texture @@ -45,9 +44,9 @@ namespace drawinglayer void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const { // base implementation creates random color (for testing only, may also be pure virtual) - rBColor.setRed((rand() & 0x7fff) / 32767.0); - rBColor.setGreen((rand() & 0x7fff) / 32767.0); - rBColor.setBlue((rand() & 0x7fff) / 32767.0); + rBColor.setRed(tools::getRandomColorRange()); + rBColor.setGreen(tools::getRandomColorRange()); + rBColor.setBlue(tools::getRandomColorRange()); } void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const -- cgit