path: root/sc/source
diff options
authorTor Lillqvist <>2015-01-20 16:24:14 +0200
committerMichael Meeks <>2015-01-21 07:21:19 +0000
commitdad7161cc30b335a108c7850f453877a161969ae (patch)
treeb0b093ffe95b869a94fe3de283e33baff7254c4c /sc/source
parentcd5f69376bf27275d92073943451b8b72a708d04 (diff)
fdo88632: Make the Calc random functions non-random when requested
We don't want such a mode to affect other uses of randomness, though. Thus use a separate random number generator object for these two functions, and use a fixed seed for it if the SC_RAND_REPEATABLE environment variable is set. As RAND() is implemented in sc, and RANDBETWEEN() is implemented in scaddins, it was a bit hard to figure out where to add the new functions needed, without having to over-engineer things with UNO. (This functionality is totally Calc-specific, but neither sc nor scaddins has any public (non-UNO) API.) Caolan suggested the formula module, which seems like a good enough place to me. Change-Id: Ic1c9ca165278d53036598b03b13b4ffbdc98a75e Reviewed-on: Reviewed-by: Michael Meeks <> Tested-by: Michael Meeks <>
Diffstat (limited to 'sc/source')
2 files changed, 4 insertions, 3 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index a5648e3cef11..948b4ab1d331 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -16,7 +16,7 @@
#include "tokenarray.hxx"
#include "compiler.hxx"
#include "interpre.hxx"
-#include <comphelper/random.hxx>
+#include <formula/random.hxx>
#include <formula/vectortoken.hxx>
#include "scmatrix.hxx"
@@ -654,7 +654,7 @@ threefry2x32 (threefry2x32_ctr_t in, threefry2x32_key_t k)\n\
/// Create buffer and pass the buffer to a given kernel
virtual size_t Marshal( cl_kernel k, int argno, int, cl_program ) SAL_OVERRIDE
- cl_int seed = comphelper::rng::uniform_int_distribution(0, SAL_MAX_INT32);
+ cl_int seed = formula::rng::nRandom(0, SAL_MAX_INT32);
// Pass the scalar result back to the rest of the formula kernel
cl_int err = clSetKernelArg(k, argno, sizeof(cl_int), (void*)&seed);
if (CL_SUCCESS != err)
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 01343a5f1272..f01137a45216 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -22,6 +22,7 @@
#include "scitems.hxx"
#include <editeng/langitem.hxx>
#include <editeng/justifyitem.hxx>
+#include <formula/random.hxx>
#include <osl/thread.h>
#include <svx/algitem.hxx>
#include <unotools/textsearch.hxx>
@@ -1662,7 +1663,7 @@ void ScInterpreter::ScPi()
void ScInterpreter::ScRandom()
- PushDouble(::comphelper::rng::uniform_real_distribution());
+ PushDouble(formula::rng::fRandom(0, 1));
void ScInterpreter::ScTrue()