source: XMLIO_V2/external/include/random/default.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1#ifndef BZ_RANDOM_DEFAULT_H
2#define BZ_RANDOM_DEFAULT_H
3
4#include <random/mt.h>
5
6BZ_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
15typedef 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
22struct sharedState { };
23struct independentState { };
24typedef sharedState defaultState;
25
26typedef 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
36template<typename IRNG, typename state>
37class IRNGWrapper {
38};
39
40template<typename IRNG>
41class IRNGWrapper<IRNG,sharedState> {
42
43public:
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
53protected:
54    static IRNG irng_;
55};
56
57template<typename IRNG>
58IRNG IRNGWrapper<IRNG,sharedState>::irng_;
59
60template<typename IRNG>
61class IRNGWrapper<IRNG,independentState> {
62
63public:
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
73protected:
74    IRNG irng_;
75};
76
77// defaultIRNG is a type alias for the default Integer Random
78// Number Generator (IRNG).
79
80typedef MersenneTwister defaultIRNG;
81
82BZ_NAMESPACE_END
83
84#endif // BZ_RANDOM_DEFAULT_H
85
Note: See TracBrowser for help on using the repository browser.