Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RandomGenerator.h

Go to the documentation of this file.
00001 
00006 #ifndef Impala_Util_RandomGenerator_h
00007 #define Impala_Util_RandomGenerator_h
00008 
00009 #include <ctime>
00010 #include <cstdlib>
00011 
00012 namespace Impala
00013 {
00014 namespace Util
00015 {
00016     
00017 class RandomGenerator
00018 {
00019 public:
00021     static RandomGenerator&
00022     GetInstance()
00023     {
00024         static RandomGenerator theRandomGenerator;
00025         return theRandomGenerator;
00026     }
00027     
00029     static void
00030     RandomizeSeed()
00031     {
00032         std::srand(time(0));
00033     }
00034     
00036     static int
00037     GenerateInt(int i = RAND_MAX)
00038     {
00039         return (int) (((double) std::rand() / ((double) RAND_MAX + 1.0)) * (i+1));
00040     }
00041     
00043     static double
00044     GenerateDouble(double i = 1)
00045     {
00046         return (double) (((double) std::rand() / ((double) RAND_MAX + 1.0)) * (i));
00047     }
00048     
00049     static void
00050     PermutateVector(std::vector<int>& items)
00051     {
00052         int endIndex = items.size();
00053         while(endIndex > 1)
00054         {
00055             endIndex--;
00056             int pick = GenerateInt(endIndex);
00057             int temp = items[pick];
00058             items[pick] = items[endIndex];
00059             items[endIndex] = temp;
00060         }
00061     }
00062     
00063 private:
00064     // Constructor
00065     RandomGenerator()
00066     {
00067     }
00068     
00069     //Copy Constructor
00070     RandomGenerator(const RandomGenerator&)
00071     {
00072     }
00073     
00074     // Assignment Operator
00075     RandomGenerator&
00076     operator=(const RandomGenerator&)
00077     {
00078     }
00079 }; // end class RandomGenerator
00080     
00081 
00082 } // namespace Util
00083 } // namespace Impala
00084 
00085 #endif

Generated on Fri Mar 19 09:31:47 2010 for ImpalaSrc by  doxygen 1.5.1