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 --- include/comphelper/random.hxx | 21 +++++++++++++++++---- include/drawinglayer/tools/converters.hxx | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/comphelper/random.hxx b/include/comphelper/random.hxx index 6b5d6eb86377..e7051a860403 100644 --- a/include/comphelper/random.hxx +++ b/include/comphelper/random.hxx @@ -18,11 +18,24 @@ namespace comphelper namespace rng { -/// set initial seed (equivalent of libc srand()) -COMPHELPER_DLLPUBLIC void seed(int i); +/// reset initial seed, typically you don't call this as the initial seed is taken from the +// time on the first use of the distribution functions +COMPHELPER_DLLPUBLIC void reseed(int i); -/// uniform distribution in [0,1) -COMPHELPER_DLLPUBLIC double uniform(); +// note that uniform_int_distribution is inclusive of b, i.e. [a,b] while +// uniform_real_distribution is exclusive of b, i.e. [a,b), [std/boost]::nextafter may be your friend there + +/// uniform distribution in [a,b) +COMPHELPER_DLLPUBLIC double uniform_real_distribution(double a = 0.0, double b = 1.0); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC int uniform_int_distribution(int a, int b); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC unsigned int uniform_int_distribution(unsigned int a, unsigned int b); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC size_t uniform_int_distribution(size_t a, size_t b); } // namespace diff --git a/include/drawinglayer/tools/converters.hxx b/include/drawinglayer/tools/converters.hxx index 957973f8bda1..c004e25a7a3c 100644 --- a/include/drawinglayer/tools/converters.hxx +++ b/include/drawinglayer/tools/converters.hxx @@ -37,6 +37,8 @@ namespace drawinglayer sal_uInt32 nDiscreteHeight, sal_uInt32 nMaxQuadratPixels); + double DRAWINGLAYER_DLLPUBLIC getRandomColorRange(); + } // end of namespace tools } // end of namespace drawinglayer -- cgit