random_numbers.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef RANDOM_NUMBERS_RANDOM_NUMBERS_
38 #define RANDOM_NUMBERS_RANDOM_NUMBERS_
39 
40 #include <boost/random/mersenne_twister.hpp>
41 #include <boost/random/uniform_real.hpp>
42 #include <boost/random/uniform_int.hpp>
43 #include <boost/random/variate_generator.hpp>
44 #include <boost/random/normal_distribution.hpp>
45 
46 namespace random_numbers
47 {
55 {
56 public:
59 
61  RandomNumberGenerator(boost::uint32_t seed);
62 
64  double uniform01(void)
65  {
66  return uni_();
67  }
68 
74  double uniformReal(double lower_bound, double upper_bound)
75  {
76  return (upper_bound - lower_bound) * uni_() + lower_bound;
77  }
78 
80  double gaussian01(void)
81  {
82  return normal_();
83  }
84 
86  double gaussian(double mean, double stddev)
87  {
88  return normal_() * stddev + mean;
89  }
90 
94  void quaternion(double value[4]);
95 
97  int uniformInteger(int min, int max)
98  {
99  boost::uniform_int<> dis(min, max);
100  return dis(generator_);
101  }
102 
107  boost::uint32_t getFirstSeed();
108 
109 private:
110  boost::mt19937 generator_;
111  boost::uniform_real<> uniDist_;
112  boost::normal_distribution<> normalDist_;
113  boost::variate_generator<boost::mt19937&, boost::uniform_real<> > uni_;
114  boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > normal_;
115 };
116 } // namespace random_numbers
117 
118 #endif
double gaussian(double mean, double stddev)
Generate a random real using a normal distribution with given mean and variance.
int uniformInteger(int min, int max)
Generate an integer uniformly at random within a specified range (inclusive)
void quaternion(double value[4])
Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w) ...
double uniform01(void)
Generate a random real between 0 and 1.
boost::uint32_t getFirstSeed()
Allow the randomly generated seed to be saved so that experiments / benchmarks can be recreated in th...
boost::variate_generator< boost::mt19937 &, boost::normal_distribution<> > normal_
double uniformReal(double lower_bound, double upper_bound)
Generate a random real within given bounds: [lower_bound, upper_bound)
double gaussian01(void)
Generate a random real using a normal distribution with mean 0 and variance 1.
boost::normal_distribution normalDist_
boost::variate_generator< boost::mt19937 &, boost::uniform_real<> > uni_
RandomNumberGenerator(void)
Constructor. Always sets a "random" random seed.
Random number generation (wrapper for boost). An instance of this class cannot be used by multiple th...


random_numbers
Author(s): Ioan Sucan
autogenerated on Thu Apr 1 2021 02:44:44