SimpleNonRepeatRandomNG.h

Go to the documentation of this file.
00001 #ifndef SIMPLENONREPEATRANDOMNG_H_
00002 #define SIMPLENONREPEATRANDOMNG_H_
00003 
00004 #include "RandomDistribution.h"
00005 
00006 #include <vector>
00007 
00008 #include <algorithm>
00009 using std::swap;
00010 
00011 
00020 class SimpleNonRepeatRandomNG
00021 {
00022 public:
00023     SimpleNonRepeatRandomNG();
00024 
00025     SimpleNonRepeatRandomNG(int low, int high);
00026 
00027     virtual ~SimpleNonRepeatRandomNG();
00028 
00029     //void setEngine(RandomEngine *engine)
00030     //{
00031     //    unidist.setEngine(engine);
00032     //}
00033 
00034     //void seed(int seed)
00035     //{
00036     //    unidist.seed(seed);
00037     //}
00038 
00039     void reset(int numElem)
00040     {
00041         // rewind the generated numbers
00042         if (cursor) {
00043             rewind();
00044         }
00045         generated_numbers.resize(0);            
00046         generated_numbers.reserve(numElem);
00047         num_elem = numElem;
00048     }
00049 
00050     void rewind()
00051     {
00052         // rewind the generated numbers
00053         while (cursor) {
00054             cursor--;
00055             swap(seq_array[cursor], seq_array[cursor + generated_numbers[cursor]]);
00056         }
00057     }
00058 
00059     void reset(int low, int high, int numElem)
00060     {
00061         this->low = low;
00062         this->high = high;
00063         num_elem = numElem;
00064         reset(numElem);
00065         // reinit the sequence array        
00066         if (seq_array)
00067             delete [] seq_array;
00068         range = high-low+1;
00069         seq_array = new int[range];
00070         for (int i = 0; i < range; ++i)
00071             seq_array[i] = i;
00072     };
00073 
00074     int operator()( RandomEngine &eng );
00075 
00076 protected:
00077     int * seq_array;
00078 
00079     std::vector< int > generated_numbers;
00080 
00081     int low;
00082 
00083     int high;
00084 
00085     int range;
00086 
00087     int cursor;
00088 
00089     int num_elem;
00090 
00091     UniformDistribution unidist;
00092 
00093     bool reseted;
00094 
00095 };
00096 
00097 #endif /*SIMPLENONREPEATRANDOMNG_H_*/

Generated on Wed Jul 9 16:34:39 2008 for PCSIM by  doxygen 1.5.5