All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rand.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: Random number generator
18  * Author: Nate Koenig
19  * Date: 27 May 2009
20  */
21 
22 #ifndef _RAND_HH_
23 #define _RAND_HH_
24 
25 #include <boost/random.hpp>
26 
27 namespace gazebo
28 {
29  namespace math
30  {
33  typedef boost::mt19937 GeneratorType;
36  typedef boost::uniform_real<double> UniformRealDist;
39  typedef boost::normal_distribution<double> NormalRealDist;
42  typedef boost::uniform_int<int> UniformIntDist;
43 
46  typedef boost::variate_generator<GeneratorType&, UniformRealDist > URealGen;
49  typedef boost::variate_generator<GeneratorType&, NormalRealDist > NRealGen;
52  typedef boost::variate_generator<GeneratorType&, UniformIntDist > UIntGen;
53 
56 
59  class Rand
60  {
64  public: static void SetSeed(uint32_t _seed);
65 
69  public: static uint32_t GetSeed();
70 
74  public: static double GetDblUniform(double _min = 0, double _max = 1);
75 
79  public: static double GetDblNormal(double _mean = 0, double _sigma = 1);
80 
84  public: static int GetIntUniform(int _min, int _max);
85 
89  public: static int GetIntNormal(int _mean, int _sigma);
90 
91  // The random number generator
92  private: static GeneratorType *randGenerator;
93 
94  private: static uint32_t seed;
95  };
97  }
98 }
99 #endif
100