00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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 #ifndef OMPL_UTIL_RANDOM_NUMBERS_
00038 #define OMPL_UTIL_RANDOM_NUMBERS_
00039
00040 #include <boost/random/mersenne_twister.hpp>
00041 #include <boost/random/uniform_real.hpp>
00042 #include <boost/random/normal_distribution.hpp>
00043 #include <boost/random/variate_generator.hpp>
00044 #include <cassert>
00045
00046 namespace ompl
00047 {
00054 class RNG
00055 {
00056 public:
00057
00059 RNG(void);
00060
00062 double uniform01(void)
00063 {
00064 return uni_();
00065 }
00066
00068 double uniformReal(double lower_bound, double upper_bound)
00069 {
00070 assert(lower_bound <= upper_bound);
00071 return (upper_bound - lower_bound) * uni_() + lower_bound;
00072 }
00073
00075 int uniformInt(int lower_bound, int upper_bound)
00076 {
00077 int r = (int)floor(uniformReal((double)lower_bound, (double)(upper_bound) + 1.0));
00078 return (r > upper_bound) ? upper_bound : r;
00079 }
00080
00082 bool uniformBool(void)
00083 {
00084 return uni_() <= 0.5;
00085 }
00086
00088 double gaussian01(void)
00089 {
00090 return normal_();
00091 }
00092
00094 double gaussian(double mean, double stddev)
00095 {
00096 return normal_() * stddev + mean;
00097 }
00098
00104 double halfNormalReal(double r_min, double r_max, double focus = 3.0);
00105
00109 int halfNormalInt(int r_min, int r_max, double focus = 3.0);
00110
00112 void quaternion(double value[4]);
00113
00117 static void setSeed(boost::uint32_t seed);
00118
00123 static boost::uint32_t getSeed(void);
00124
00125 private:
00126
00127 boost::mt19937 generator_;
00128 boost::uniform_real<> uniDist_;
00129 boost::normal_distribution<> normalDist_;
00130 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > uni_;
00131 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > normal_;
00132
00133 };
00134
00135 }
00136
00137 #endif