summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-10-03 17:12:23 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-10-06 14:13:27 +0100
commit8f436d3de7e99268a8862664d2cb2574231c3b18 (patch)
tree0a07dd3cecbd7bc5b0293006bb8691e33c5cca75 /sc
parente5ab3685550cf35c3eb9cb47530044f2d86433d5 (diff)
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
Diffstat (limited to 'sc')
-rw-r--r--sc/Library_scopencl.mk1
-rw-r--r--sc/source/core/data/global.cxx2
-rw-r--r--sc/source/core/data/table3.cxx5
-rw-r--r--sc/source/core/opencl/opencl_device.cxx4
-rw-r--r--sc/source/core/tool/interpr1.cxx2
-rw-r--r--sc/source/core/tool/interpr3.cxx3
-rw-r--r--sc/source/ui/StatisticsDialogs/SamplingDialog.cxx13
7 files changed, 11 insertions, 19 deletions
diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk
index 3e6b955638ca..5f60a3736a26 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Library_use_externals,scopencl,\
))
$(eval $(call gb_Library_use_libraries,scopencl,\
+ comphelper \
cppu \
cppuhelper \
for \
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index 9b4e63e6f26a..ae9e84c299b4 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -521,8 +521,6 @@ void ScGlobal::Init()
// arguments are to be merged in, which in turn need strings of function
// names from the compiler.
ScParameterClassification::Init();
- srand( (unsigned) time( NULL ) ); // Random Seed Init for Interpreter
- ::comphelper::rng::seed( time( NULL ) ); // seed for libc rand() replacement
InitAddIns();
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 7d5d79f2eac7..e41458b9e9d7 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -18,6 +18,7 @@
*/
#include <rtl/math.hxx>
+#include <comphelper/random.hxx>
#include <unotools/textsearch.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
@@ -1287,10 +1288,10 @@ bool ScTable::IsSorted( SCCOLROW nStart, SCCOLROW nEnd ) const // ueber aSortP
void ScTable::DecoladeRow( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2 )
{
SCROW nRow;
- SCROW nMax = nRow2 - nRow1;
+ int nMax = nRow2 - nRow1;
for (SCROW i = nRow1; (i + 4) <= nRow2; i += 4)
{
- nRow = rand() % nMax;
+ nRow = comphelper::rng::uniform_int_distribution(0, nMax-1);
pArray->Swap(i, nRow1 + nRow);
}
}
diff --git a/sc/source/core/opencl/opencl_device.cxx b/sc/source/core/opencl/opencl_device.cxx
index 0dec2673ffb7..6b99758dacc3 100644
--- a/sc/source/core/opencl/opencl_device.cxx
+++ b/sc/source/core/opencl/opencl_device.cxx
@@ -20,6 +20,7 @@
#include <iostream>
#include <sstream>
#include <vector>
+#include <comphelper/random.hxx>
#include <boost/scoped_ptr.hpp>
#include "opencl_device.hxx"
@@ -170,13 +171,12 @@ double timerCurrent(timer* mytimer)
/* Random number generator */
double random(double min, double max)
{
- return floor(((double)rand() / ((unsigned int)RAND_MAX + 1)) * (max - min + 1) + min);
+ return comphelper::rng::uniform_real_distribution(min, max);
}
/* Populate input */
void populateInput(LibreOfficeDeviceEvaluationIO* testData)
{
- srand((unsigned int)time(NULL));
double* input0 = &testData->input0[0];
double* input1 = &testData->input1[0];
double* input2 = &testData->input2[0];
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 7c7dff39d349..358dab006806 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1662,7 +1662,7 @@ void ScInterpreter::ScPi()
void ScInterpreter::ScRandom()
{
- PushDouble(::comphelper::rng::uniform());
+ PushDouble(::comphelper::rng::uniform_real_distribution());
}
void ScInterpreter::ScTrue()
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 685e3724a8b0..7b97d598ff2b 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -34,6 +34,7 @@
#include <vector>
#include <algorithm>
#include <boost/math/special_functions/log1p.hpp>
+#include <comphelper/random.hxx>
using ::std::vector;
using namespace formula;
@@ -3819,7 +3820,7 @@ void ScInterpreter::QuickSort( vector<double>& rSortArray, vector<long>* pIndexO
size_t nValCount = rSortArray.size();
for (size_t i = 0; (i + 4) <= nValCount-1; i += 4)
{
- size_t nInd = rand() % (int) (nValCount-1);
+ size_t nInd = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), nValCount-2);
::std::swap( rSortArray[i], rSortArray[nInd]);
if (pIndexOrder)
::std::swap( pIndexOrder->at(i), pIndexOrder->at(nInd));
diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
index 49b2d4315577..a88faafd1f64 100644
--- a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
@@ -11,7 +11,7 @@
#include <sfx2/dispatch.hxx>
#include <svl/zforlist.hxx>
#include <svl/undo.hxx>
-
+#include <comphelper/random.hxx>
#include "rangelst.hxx"
#include "scitems.hxx"
#include "docsh.hxx"
@@ -22,8 +22,6 @@
#include "docfunc.hxx"
#include "StatisticsDialogs.hrc"
-#include <boost/random.hpp>
-
#include "SamplingDialog.hxx"
ScSamplingDialog::ScSamplingDialog(
@@ -203,11 +201,6 @@ ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell* pDocShell)
SCCOL outCol = mOutputAddress.Col();
SCROW outRow = mOutputAddress.Row();
- TimeValue now;
- osl_getSystemTime(&now);
- boost::mt19937 seed(now.Nanosec);
- boost::uniform_01<boost::mt19937> rng(seed);
-
SCROW inRow;
sal_Int64 aSampleSize = mpSampleSize->GetValue();
@@ -222,11 +215,9 @@ ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell* pDocShell)
outRow = mOutputAddress.Row();
inRow = aStart.Row();
- double aRandomValue;
-
while ((outRow - mOutputAddress.Row()) < aSampleSize)
{
- aRandomValue = rng();
+ double aRandomValue = comphelper::rng::uniform_real_distribution();
if ( (aPopulationSize - (inRow - aStart.Row())) * aRandomValue >= aSampleSize - (outRow - mOutputAddress.Row()) )
{