blitz
Version 0.9
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
random
default.h
Go to the documentation of this file.
1
#ifndef BZ_RANDOM_DEFAULT_H
2
#define BZ_RANDOM_DEFAULT_H
3
4
#include <
random/mt.h
>
5
6
BZ_NAMESPACE
(ranlib)
7
8
// Some terminology:
9
// IRNG = Integer Random Number Generator. IRNGs generate random
10
// integers, which are used to create floating-point random
11
// numbers.
12
// RNG = Random Number Generator. RNGs use IRNGs to create floating-
13
// point random numbers following desired distributions.
14
15
typedef
float
defaultType
;
16
17
// These are type tags. A RNG with sharedState shares an IRNG
18
// with other RNGs. An RNG with independentState
19
// contains its own IRNG. Generally, sharedState RNGs should be
20
// used.
21
22
struct
sharedState
{ };
23
struct
independentState
{ };
24
typedef
sharedState
defaultState
;
25
26
typedef
unsigned
int
IRNG_int
;
27
28
29
// IRNGWrapper handles shared and independent state IRNGs.
30
// If a class inherits from IRNGWrapper<IRNG,sharedState>,
31
// it gets a static IRNG (i.e. the IRNG state is shared among
32
// all RNGs); if it inherits from IRNGWrapper<IRNG,independentState>,
33
// it gets an independent IRNG (the IRNG state is encapsulated
34
// in the RNG, and is not shared among RNGs).
35
36
template
<
typename
IRNG,
typename
state>
37
class
IRNGWrapper
{
38
};
39
40
template
<
typename
IRNG>
41
class
IRNGWrapper
<IRNG,
sharedState
> {
42
43
public
:
44
void
seed(
IRNG_int
x)
45
{ irng_.seed(x); }
46
47
typedef
typename
IRNG::T_state
T_state
;
48
T_state
getState
()
const
{
return
irng_.getState(); }
49
std::string
getStateString
()
const
{
return
irng_.getStateString(); }
50
void
setState
(
const
T_state
&
s
) { irng_.setState(s); }
51
void
setState
(
const
std::string&
s
) { irng_.setState(s); }
52
53
protected
:
54
static
IRNG
irng_
;
55
};
56
57
template
<
typename
IRNG>
58
IRNG
IRNGWrapper<IRNG,sharedState>::irng_
;
59
60
template
<
typename
IRNG>
61
class
IRNGWrapper
<IRNG,
independentState
> {
62
63
public
:
64
void
seed(
IRNG_int
x)
65
{ irng_.seed(x); }
66
67
typedef
typename
IRNG::T_state
T_state
;
68
T_state
getState
()
const
{
return
irng_.getState(); }
69
std::string
getStateString
()
const
{
return
irng_.getStateString(); }
70
void
setState
(
const
T_state
&
s
) { irng_.setState(s); }
71
void
setState
(
const
std::string&
s
) { irng_.setState(s); }
72
73
protected
:
74
IRNG
irng_
;
75
};
76
77
// defaultIRNG is a type alias for the default Integer Random
78
// Number Generator (IRNG).
79
80
typedef
MersenneTwister
defaultIRNG
;
81
82
BZ_NAMESPACE_END
83
84
#endif // BZ_RANDOM_DEFAULT_H
85
Generated on Fri Jun 15 2012 12:01:12 for blitz by
1.8.1.1