Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / random.cxx
blob5033582f542ada48959786023021b3eba61727fb
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/.
9 * Contributor(s):
10 * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de>
13 #include <boost/random.hpp>
15 // this is nothing but a simple wrapper around
16 // the boost random generators
18 namespace sc
20 namespace rng
23 // underlying random number generator
24 // boost::mt19937 implements the Mersenne twister algorithm which
25 // is fast and has good statistical properties, it produces integers
26 // in the range of [0, 2^32-1] internally
27 // memory requirement: 625*sizeof(uint32_t)
28 // http://en.wikipedia.org/wiki/Mersenne_twister
29 #define BOOST_RNG_ALGO boost::mt19937
30 BOOST_RNG_ALGO global_rng;
32 // initialises the state of the global random number generator
33 // should only be called once at the start of the main programme
34 // (note, a few boost::variate_generator<> (like normal) have their
35 // own state which would need a reset as well to guarantee identical
36 // sequence of numbers, e.g. via myrand.distribution().reset())
37 void seed(int i)
39 global_rng.seed(i);
42 // uniform [0,1) or [a,b) distribution
43 double uniform()
45 static boost::uniform_01<BOOST_RNG_ALGO&> myrand(global_rng);
46 return myrand();
49 } // namespace
50 } // namespace
52 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */