diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2014-05-13 08:42:21 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2014-05-17 12:40:39 +0000 |
commit | 9c3e819f066acaf9f5a416630fa7dd83fdc2539d (patch) | |
tree | b5d4e013b34d2a0f42cf9926b4c2919bd3c414db /comphelper | |
parent | 3c1e30b77df4f34c4954bff37a08439ace7f2434 (diff) |
move boost rng wrapper from sc to comphelper
so we can re-use it in other modules
Change-Id: I6057b1e955f745019fd48f91a754279df0f2b948
Reviewed-on: https://gerrit.libreoffice.org/9348
Reviewed-by: Thomas Arnhold <thomas@arnhold.org>
Tested-by: Thomas Arnhold <thomas@arnhold.org>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/Library_comphelper.mk | 1 | ||||
-rw-r--r-- | comphelper/inc/pch/precompiled_comphelper.hxx | 3 | ||||
-rw-r--r-- | comphelper/source/misc/random.cxx | 54 |
3 files changed, 57 insertions, 1 deletions
diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk index 623bac6856c7..cfe48f631992 100644 --- a/comphelper/Library_comphelper.mk +++ b/comphelper/Library_comphelper.mk @@ -99,6 +99,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\ comphelper/source/misc/officeresourcebundle \ comphelper/source/misc/officerestartmanager \ comphelper/source/misc/proxyaggregation \ + comphelper/source/misc/random \ comphelper/source/misc/scopeguard \ comphelper/source/misc/SelectionMultiplex \ comphelper/source/misc/sequenceashashmap \ diff --git a/comphelper/inc/pch/precompiled_comphelper.hxx b/comphelper/inc/pch/precompiled_comphelper.hxx index ab660b17a755..36ec107aefb0 100644 --- a/comphelper/inc/pch/precompiled_comphelper.hxx +++ b/comphelper/inc/pch/precompiled_comphelper.hxx @@ -18,6 +18,7 @@ #include <boost/bind.hpp> #include <boost/current_function.hpp> #include <boost/noncopyable.hpp> +#include <boost/random.hpp> #include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> @@ -62,7 +63,6 @@ #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/datatransfer/XTransferable.hpp> -#include <com/sun/star/document/NoSuchFilterRequest.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XTypeDetection.hpp> @@ -225,4 +225,5 @@ #include <unicode/uchar.h> #include <uno/data.h> #include <vector> + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/source/misc/random.cxx b/comphelper/source/misc/random.cxx new file mode 100644 index 000000000000..a97608649bbf --- /dev/null +++ b/comphelper/source/misc/random.cxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Contributor(s): + * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de> + */ + +#include <boost/random.hpp> + +#include <comphelper/random.hxx> + +// this is nothing but a simple wrapper around +// the boost random generators + +namespace comphelper +{ +namespace rng +{ + +// underlying random number generator +// boost::mt19937 implements the Mersenne twister algorithm which +// is fast and has good statistical properties, it produces integers +// in the range of [0, 2^32-1] internally +// memory requirement: 625*sizeof(uint32_t) +// http://en.wikipedia.org/wiki/Mersenne_twister +#define BOOST_RNG_ALGO boost::mt19937 +BOOST_RNG_ALGO global_rng; + +// initialises the state of the global random number generator +// should only be called once at the start of the main programme +// (note, a few boost::variate_generator<> (like normal) have their +// own state which would need a reset as well to guarantee identical +// sequence of numbers, e.g. via myrand.distribution().reset()) +void seed(int i) +{ + global_rng.seed(i); +} + +// uniform [0,1) or [a,b) distribution +double uniform() +{ + static boost::uniform_01<BOOST_RNG_ALGO&> myrand(global_rng); + return myrand(); +} + +} // namespace +} // namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |