1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
14 #include <formula/random.hxx>
15 #include <rtl/instance.hxx>
19 struct CalcFormulaRandomGenerator
22 CalcFormulaRandomGenerator()
24 // initialises the state of this RNG.
25 // should only be called once.
26 bool bRepeatable
= (getenv("SC_RAND_REPEATABLE") != 0);
27 aRng
.seed(bRepeatable
? 42 : time(NULL
));
31 class theCalcFormulaRandomGenerator
: public rtl::Static
<CalcFormulaRandomGenerator
, theCalcFormulaRandomGenerator
> {};
41 double fRandom(double a
, double b
)
43 std::uniform_real_distribution
<double> dist(a
, b
);
44 return dist(theCalcFormulaRandomGenerator::get().aRng
);
47 sal_Int32
nRandom(sal_Int32 a
, sal_Int32 b
)
49 std::uniform_int_distribution
<sal_Int32
> dist(a
, b
);
50 return dist(theCalcFormulaRandomGenerator::get().aRng
);
56 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */