Kaydet (Commit) 18ad91ee authored tarafından Caolán McNamara's avatar Caolán McNamara

boost::random->std::random

Change-Id: I1b823b6c17b731e427bff88c6fff7897f66ddb5c
üst f86a1dbf
...@@ -10,12 +10,13 @@ ...@@ -10,12 +10,13 @@
* Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de> * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de>
*/ */
#include <boost/random.hpp>
#include <comphelper/random.hxx> #include <comphelper/random.hxx>
#include <rtl/instance.hxx> #include <rtl/instance.hxx>
#include <assert.h>
#include <random>
// this is nothing but a simple wrapper around // this is nothing but a simple wrapper around
// the boost random generators // the std::random generators
namespace comphelper namespace comphelper
{ {
...@@ -23,21 +24,21 @@ namespace rng ...@@ -23,21 +24,21 @@ namespace rng
{ {
// underlying random number generator // underlying random number generator
// boost::mt19937 implements the Mersenne twister algorithm which // std::mt19937 implements the Mersenne twister algorithm which
// is fast and has good statistical properties, it produces integers // is fast and has good statistical properties, it produces integers
// in the range of [0, 2^32-1] internally // in the range of [0, 2^32-1] internally
// memory requirement: 625*sizeof(uint32_t) // memory requirement: 625*sizeof(uint32_t)
// http://en.wikipedia.org/wiki/Mersenne_twister // http://en.wikipedia.org/wiki/Mersenne_twister
#define BOOST_RNG_ALGO boost::mt19937 #define STD_RNG_ALGO std::mt19937
struct RandomNumberGenerator struct RandomNumberGenerator
{ {
BOOST_RNG_ALGO global_rng; STD_RNG_ALGO global_rng;
RandomNumberGenerator() RandomNumberGenerator()
{ {
// initialises the state of the global random number generator // initialises the state of the global random number generator
// should only be called once. // should only be called once.
// (note, a few boost::variate_generator<> (like normal) have their // (note, a few std::variate_generator<> (like normal) have their
// own state which would need a reset as well to guarantee identical // own state which would need a reset as well to guarantee identical
// sequence of numbers, e.g. via myrand.distribution().reset()) // sequence of numbers, e.g. via myrand.distribution().reset())
global_rng.seed(time(NULL)); global_rng.seed(time(NULL));
...@@ -55,21 +56,21 @@ void reseed(int i) ...@@ -55,21 +56,21 @@ void reseed(int i)
// uniform ints [a,b] distribution // uniform ints [a,b] distribution
int uniform_int_distribution(int a, int b) int uniform_int_distribution(int a, int b)
{ {
boost::random::uniform_int_distribution<int> dist(a, b); std::uniform_int_distribution<int> dist(a, b);
return dist(theRandomNumberGenerator::get().global_rng); return dist(theRandomNumberGenerator::get().global_rng);
} }
// uniform ints [a,b] distribution // uniform ints [a,b] distribution
unsigned int uniform_uint_distribution(unsigned int a, unsigned int b) unsigned int uniform_uint_distribution(unsigned int a, unsigned int b)
{ {
boost::random::uniform_int_distribution<unsigned int> dist(a, b); std::uniform_int_distribution<unsigned int> dist(a, b);
return dist(theRandomNumberGenerator::get().global_rng); return dist(theRandomNumberGenerator::get().global_rng);
} }
// uniform size_t [a,b] distribution // uniform size_t [a,b] distribution
size_t uniform_size_distribution(size_t a, size_t b) size_t uniform_size_distribution(size_t a, size_t b)
{ {
boost::random::uniform_int_distribution<size_t> dist(a, b); std::uniform_int_distribution<size_t> dist(a, b);
return dist(theRandomNumberGenerator::get().global_rng); return dist(theRandomNumberGenerator::get().global_rng);
} }
...@@ -77,7 +78,7 @@ size_t uniform_size_distribution(size_t a, size_t b) ...@@ -77,7 +78,7 @@ size_t uniform_size_distribution(size_t a, size_t b)
double uniform_real_distribution(double a, double b) double uniform_real_distribution(double a, double b)
{ {
assert(a < b); assert(a < b);
boost::random::uniform_real_distribution<double> dist(a, b); std::uniform_real_distribution<double> dist(a, b);
return dist(theRandomNumberGenerator::get().global_rng); return dist(theRandomNumberGenerator::get().global_rng);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment