00001 #ifndef RANDGENDummy_HPP_
00002 #define RANDGENDummy_HPP_
00003
00004 #include "../../RandGen.hpp"
00005
00006 class RandGenDummy: public RandGen
00007 {
00008 private:
00009 unsigned int i;
00010 int inc;
00011
00012 unsigned int d_rand()
00013 {
00014 if (!RandGen::init)
00015 {
00016 initialize();
00017 RandGen::init = true;
00018 }
00019
00020 i += inc;
00021
00022 return i;
00023 }
00024
00025 public:
00026
00027 RandGenDummy() :
00028 RandGen()
00029 {
00030 inc = 1;
00031 }
00032
00033 RandGenDummy(long seed, int _inc = 1) :
00034 inc(_inc), RandGen(seed)
00035 {
00036 }
00037
00038 using RandGen::rand;
00039
00040
00041 void initialize()
00042 {
00043 i = RandGen::seed;
00044 }
00045
00046
00047 int rand()
00048 {
00049 return d_rand();
00050 }
00051
00052
00053 int rand(int n)
00054 {
00055 return d_rand() % n;
00056 }
00057
00058
00059 double rand01()
00060 {
00061 return rand(1000) / 1000.0;
00062 }
00063
00064
00065 virtual double randG()
00066 {
00067 float x, w, y;
00068 float x_, _x, w_;
00069 do
00070 {
00071 x = 2.0 * rand01() - 1.0;
00072 w = x * x + x * x;
00073
00074
00075
00076
00077
00078 x_ = (rand(200) / 100.0) - 1.0;
00079 _x = ((200 - rand(200)) / 100.0) - 1.0;
00080 w_ = (x_ * x_ + _x * _x);
00081 if ((w >= 1.0) && (w_ < w))
00082 {
00083 w = w_;
00084 x = _x;
00085 }
00086
00087
00088 } while (w >= 1.0);
00089
00090 w = sqrt((-2.0 * log(w)) / w);
00091 y = x * w;
00092
00093 return y;
00094 }
00095 };
00096
00097 #endif