00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef RNG_BIT_REVERSE_H
00012 #define RNG_BIT_REVERSE_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Utility/SequenceGen.h"
00039
00040
00041 class RNGBitReverse {
00042
00043 public:
00044
00045 typedef double Return_t;
00046
00047 public:
00048
00049 RNGBitReverse(unsigned int base = 2, unsigned long seed = 1)
00050 : Base(base), Seed(seed) {}
00051
00052
00053 RNGBitReverse(const RNGBitReverse& brg)
00054 : Base(brg.Base), Seed(brg.Seed) {}
00055
00056
00057 ~RNGBitReverse(void) {}
00058
00059
00060 inline void AdvanceSeed(unsigned long n = 0) { Seed += n; }
00061
00062
00063 inline void SetSeed(unsigned long seed) { Seed = seed; }
00064
00065
00066 inline void SetBase(unsigned int base) { Base = base; }
00067
00068
00069 inline unsigned long GetSeed(void) const { return Seed; }
00070
00071
00072 inline unsigned int GetBase(void) const { return Base; }
00073
00074
00075 inline Return_t GetRandom(void) const {
00076 Return_t rev = 0.0;
00077 Return_t power = 1.0;
00078 long inum = Seed;
00079 while (inum > 0) {
00080 int iquot = inum/Base;
00081 int irem = inum - iquot*Base;
00082 power /= Return_t(Base);
00083 rev += Return_t(irem)*power;
00084 inum = iquot;
00085 }
00086 Seed++;
00087 return rev;
00088 }
00089
00090
00091 inline Return_t operator()(void) const { return GetRandom(); }
00092
00093
00094 inline operator Return_t() const { return GetRandom(); }
00095
00096 private:
00097
00098 unsigned int Base;
00099 mutable unsigned long Seed;
00100 };
00101
00102 RNG_BASIC_MATH(RNGBitReverse)
00103
00104
00105
00106
00107
00108
00109
00110 class RNGBitReverseSequence : public SequenceGen<RNGBitReverse> {
00111
00112 public:
00113
00114 RNGBitReverseSequence(unsigned int base = 2, unsigned long seed = 1)
00115 : SequenceGen<RNGBitReverse>(RNGBitReverse(base,seed)) {}
00116
00117
00118 RNGBitReverseSequence(const RNGBitReverseSequence& rngseq)
00119 : SequenceGen<RNGBitReverse>(rngseq.getGenerator()) {}
00120
00121
00122 ~RNGBitReverseSequence(void) {}
00123
00124
00125 inline void AdvanceSeed(unsigned long adv = 0) {
00126 getGenerator().AdvanceSeed(adv);
00127 }
00128
00129 inline void SetSeed(unsigned long seed) { getGenerator().SetSeed(seed); }
00130 inline void SetBase(unsigned int base) { getGenerator().SetBase(base); }
00131 inline unsigned long GetSeed(void) const { return getGenerator().GetSeed(); }
00132 inline unsigned int GetBase(void) const { return getGenerator().GetBase(); }
00133
00134 inline Return_t GetRandom(void) { return getGenerator().GetRandom(); }
00135 inline Return_t operator()(void) { return getGenerator().GetRandom(); }
00136 };
00137
00138 #endif // RNG_BIT_REVERSE_H
00139
00140
00141
00142
00143
00144