blitz
Version 1.0.2
Toggle main menu visibility
Loading...
Searching...
No Matches
default.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
/***************************************************************************
3
* random/default.h Default IRNG wrapper class
4
*
5
* $Id$
6
*
7
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8
*
9
* This file is a part of Blitz.
10
*
11
* Blitz is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License
13
* as published by the Free Software Foundation, either version 3
14
* of the License, or (at your option) any later version.
15
*
16
* Blitz is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
20
*
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Suggestions: blitz-devel@lists.sourceforge.net
25
* Bugs: blitz-support@lists.sourceforge.net
26
*
27
* For more information, please see the Blitz++ Home Page:
28
* https://sourceforge.net/projects/blitz/
29
*
30
***************************************************************************/
31
32
#ifndef BZ_RANDOM_DEFAULT_H
33
#define BZ_RANDOM_DEFAULT_H
34
35
#include <
random/mt.h
>
36
37
namespace
ranlib
{
38
39
// Some terminology:
40
// IRNG = Integer Random Number Generator. IRNGs generate random
41
// integers, which are used to create floating-point random
42
// numbers.
43
// RNG = Random Number Generator. RNGs use IRNGs to create floating-
44
// point random numbers following desired distributions.
45
46
typedef
float
defaultType
;
47
48
// These are type tags. A RNG with sharedState shares an IRNG
49
// with other RNGs. An RNG with independentState
50
// contains its own IRNG. Generally, sharedState RNGs should be
51
// used.
52
53
struct
sharedState
{ };
54
struct
independentState
{ };
55
typedef
sharedState
defaultState
;
56
57
typedef
unsigned
int
IRNG_int
;
58
59
60
// IRNGWrapper handles shared and independent state IRNGs.
61
// If a class inherits from IRNGWrapper<IRNG,sharedState>,
62
// it gets a static IRNG (i.e. the IRNG state is shared among
63
// all RNGs); if it inherits from IRNGWrapper<IRNG,independentState>,
64
// it gets an independent IRNG (the IRNG state is encapsulated
65
// in the RNG, and is not shared among RNGs).
66
67
template
<
typename
IRNG,
typename
state>
68
class
IRNGWrapper
{
69
};
70
71
template
<
typename
IRNG>
72
class
IRNGWrapper
<IRNG,
sharedState
> {
73
74
public
:
75
void
seed
(
IRNG_int
x)
76
{
irng_
.seed(x); }
77
78
void
seed
(std::vector<IRNG_int> x)
79
{
irng_
.seed(x); }
80
81
typedef
typename
IRNG::T_state
T_state
;
82
T_state
getState
()
const
{
return
irng_
.getState(); }
83
std::string
getStateString
()
const
{
return
irng_
.getStateString(); }
84
void
setState
(
const
T_state
& s) {
irng_
.setState(s); }
85
void
setState
(
const
std::string& s) {
irng_
.setState(s); }
86
87
protected
:
88
static
IRNG
irng_
;
89
};
90
91
template
<
typename
IRNG>
92
IRNG
IRNGWrapper<IRNG,sharedState>::irng_
;
93
94
template
<
typename
IRNG>
95
class
IRNGWrapper
<IRNG,
independentState
> {
96
97
public
:
98
IRNGWrapper
() {};
99
IRNGWrapper
(
unsigned
int
i) :
irng_
(
MersenneTwisterCreator
::create(i)) {};
100
101
void
seed
(
IRNG_int
x)
102
{
irng_
.seed(x); }
103
104
void
seed
(std::vector<IRNG_int> x)
105
{
irng_
.seed(x); }
106
107
typedef
typename
IRNG::T_state
T_state
;
108
T_state
getState
()
const
{
return
irng_
.getState(); }
109
std::string
getStateString
()
const
{
return
irng_
.getStateString(); }
110
void
setState
(
const
T_state
& s) {
irng_
.setState(s); }
111
void
setState
(
const
std::string& s) {
irng_
.setState(s); }
112
113
protected
:
114
IRNG
irng_
;
115
};
116
117
// defaultIRNG is a type alias for the default Integer Random
118
// Number Generator (IRNG).
119
120
typedef
MersenneTwister
defaultIRNG
;
121
122
}
123
124
#endif
// BZ_RANDOM_DEFAULT_H
125
ranlib::IRNGWrapper< IRNG, independentState >::IRNGWrapper
IRNGWrapper(unsigned int i)
Definition
default.h:99
ranlib::IRNGWrapper< IRNG, independentState >::IRNGWrapper
IRNGWrapper()
Definition
default.h:98
ranlib::IRNGWrapper< IRNG, independentState >::getState
T_state getState() const
Definition
default.h:108
ranlib::IRNGWrapper< IRNG, independentState >::T_state
IRNG::T_state T_state
Definition
default.h:107
ranlib::IRNGWrapper< IRNG, independentState >::getStateString
std::string getStateString() const
Definition
default.h:109
ranlib::IRNGWrapper< IRNG, independentState >::irng_
IRNG irng_
Definition
default.h:114
ranlib::IRNGWrapper< IRNG, independentState >::setState
void setState(const T_state &s)
Definition
default.h:110
ranlib::IRNGWrapper< IRNG, independentState >::seed
void seed(IRNG_int x)
Definition
default.h:101
ranlib::IRNGWrapper< IRNG, independentState >::setState
void setState(const std::string &s)
Definition
default.h:111
ranlib::IRNGWrapper< IRNG, independentState >::seed
void seed(std::vector< IRNG_int > x)
Definition
default.h:104
ranlib::IRNGWrapper< IRNG, sharedState >::seed
void seed(IRNG_int x)
Definition
default.h:75
ranlib::IRNGWrapper< IRNG, sharedState >::getState
T_state getState() const
Definition
default.h:82
ranlib::IRNGWrapper< IRNG, sharedState >::seed
void seed(std::vector< IRNG_int > x)
Definition
default.h:78
ranlib::IRNGWrapper< IRNG, sharedState >::getStateString
std::string getStateString() const
Definition
default.h:83
ranlib::IRNGWrapper< IRNG, sharedState >::irng_
static IRNG irng_
Definition
default.h:88
ranlib::IRNGWrapper< IRNG, sharedState >::setState
void setState(const T_state &s)
Definition
default.h:84
ranlib::IRNGWrapper< IRNG, sharedState >::T_state
IRNG::T_state T_state
Definition
default.h:81
ranlib::IRNGWrapper< IRNG, sharedState >::setState
void setState(const std::string &s)
Definition
default.h:85
ranlib::IRNGWrapper
Definition
default.h:68
ranlib::MersenneTwisterCreator
This class creates MersenneTwisters with different parameters indexed by and ID number.
Definition
mt.h:323
ranlib::MersenneTwister
Definition
mt.h:76
mt.h
ranlib
Definition
beta.h:50
ranlib::defaultType
float defaultType
Definition
default.h:46
ranlib::defaultState
sharedState defaultState
Definition
default.h:55
ranlib::IRNG_int
unsigned int IRNG_int
Definition
default.h:57
ranlib::defaultIRNG
MersenneTwister defaultIRNG
Definition
default.h:120
ranlib::independentState
Definition
default.h:54
ranlib::sharedState
Definition
default.h:53
random
default.h
Generated by
1.17.0