00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef RNG_XCI_H
00012 #define RNG_XCI_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "Utility/SequenceGen.h"
00032
00033
00034 #define LONG_IS_8_BYTES (((1L<<16)<<16)<<16)
00035 #if defined(IPPL_LONGLONG)
00036 typedef long long RNlong;
00037 #else
00038 #if LONG_IS_8_BYTES
00039 typedef long RNlong;
00040 #else
00041 error
00042 #endif
00043 #endif
00044
00045 class RNGXCI {
00046
00047 public:
00048
00049 typedef double Return_t;
00050
00051 public:
00052
00053 RNGXCI(RNlong advance = 0L)
00054 : Seed(1L) { AdvanceSeed(advance); }
00055
00056
00057 RNGXCI(const RNGXCI& rng)
00058 : Seed(rng.Seed) {}
00059
00060
00061 ~RNGXCI(void) {}
00062
00063
00064 inline void AdvanceSeed(RNlong n = 0L) {
00065
00066 while( n<0 ) n += RN_PERIOD;
00067 n &= RN_MASK;
00068 RNlong gen=1L, g=RN_MULT;
00069 for( ; n; n>>=1 ) {
00070 if( n&1 ) gen = gen*g & RN_MASK;
00071 g = g*g & RN_MASK;
00072 }
00073 Seed = gen*Seed & RN_MASK;
00074 return;
00075 }
00076
00077
00078 inline void SetSeed(RNlong s) {
00079 Seed = (s|1) & RN_MASK;
00080 }
00081
00082
00083 inline RNlong GetSeed(void) const { return Seed; }
00084
00085
00086 inline Return_t GetRandom(void) const {
00087 Return_t r = Seed*RN_NORM;
00088 Seed = Seed*RN_MULT & RN_MASK;
00089 return r;
00090 }
00091
00092
00093 inline Return_t operator()(void) const { return GetRandom(); }
00094
00095
00096 inline operator Return_t() const { return GetRandom(); }
00097
00098
00099 static Return_t GetRandMax(void) { return Return_t(RN_MASK); }
00100
00101 private:
00102 mutable RNlong Seed;
00103
00104
00105 static const RNlong RN_MULT;
00106 static const RNlong RN_MOD;
00107 static const RNlong RN_PERIOD;
00108 static const double RN_NORM;
00109 static const RNlong RN_MASK;
00110 };
00111
00112 RNG_BASIC_MATH(RNGXCI)
00113
00114
00115
00116
00117
00118
00119
00120 class RNGXCISequence : public SequenceGen<RNGXCI> {
00121
00122 public:
00123
00124 RNGXCISequence(int advance = 0)
00125 : SequenceGen<RNGXCI>(RNGXCI(advance)) {}
00126
00127
00128 RNGXCISequence(const RNGXCISequence& rngseq)
00129 : SequenceGen<RNGXCI>(rngseq.getGenerator()) {}
00130
00131
00132 ~RNGXCISequence(void) {}
00133
00134
00135 inline void AdvanceSeed(RNlong adv = 0L) {
00136 getGenerator().AdvanceSeed(adv);
00137 }
00138 inline void SetSeed(RNlong seed) { getGenerator().SetSeed(seed); }
00139 inline RNlong GetSeed(void) const { return getGenerator().GetSeed(); }
00140 inline Return_t GetRandom(void) { return getGenerator().GetRandom(); }
00141 inline Return_t operator()(void) { return getGenerator().GetRandom(); }
00142 static Return_t GetRandMax(void) { return RNGXCI::GetRandMax(); }
00143 };
00144
00145
00146 #endif // RNG_XCI_H
00147
00148
00149
00150
00151
00152
00153