fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / formula / source / core / api / random.cxx
blob727262fdffd504bd4413a821d9b7465dfd517eb9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <time.h>
12 #include <random>
14 #include <formula/random.hxx>
15 #include <rtl/instance.hxx>
17 namespace {
19 struct CalcFormulaRandomGenerator
21 std::mt19937 aRng;
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> {};
35 namespace formula
38 namespace rng
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);
53 } // rng
54 } // formula
56 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */