Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
18ad91ee
Kaydet (Commit)
18ad91ee
authored
Ock 06, 2015
tarafından
Caolán McNamara
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
boost::random->std::random
Change-Id: I1b823b6c17b731e427bff88c6fff7897f66ddb5c
üst
f86a1dbf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
random.cxx
comphelper/source/misc/random.cxx
+11
-10
No files found.
comphelper/source/misc/random.cxx
Dosyayı görüntüle @
18ad91ee
...
@@ -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
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment