Rand.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace math
31  {
34  typedef boost::mt19937 GeneratorType;
37  typedef boost::uniform_real<double> UniformRealDist;
40  typedef boost::normal_distribution<double> NormalRealDist;
43  typedef boost::uniform_int<int> UniformIntDist;
44 
47  typedef boost::variate_generator<GeneratorType&, UniformRealDist > URealGen;
50  typedef boost::variate_generator<GeneratorType&, NormalRealDist > NRealGen;
53  typedef boost::variate_generator<GeneratorType&, UniformIntDist > UIntGen;
54 
57 
60  class GZ_MATH_VISIBLE Rand
61  {
65  public: static void SetSeed(uint32_t _seed);
66 
70  public: static uint32_t GetSeed();
71 
75  public: static double GetDblUniform(double _min = 0, double _max = 1);
76 
80  public: static double GetDblNormal(double _mean = 0, double _sigma = 1);
81 
85  public: static int GetIntUniform(int _min, int _max);
86 
90  public: static int GetIntNormal(int _mean, int _sigma);
91 
92  // The random number generator
93  private: static GeneratorType *randGenerator;
94 
95  private: static uint32_t seed;
96  };
98  }
99 }
100 #endif
101 
boost::mt19937 GeneratorType
Definition: Rand.hh:34
Random number generator class.
Definition: Rand.hh:60
boost::normal_distribution< double > NormalRealDist
Definition: Rand.hh:40
boost::uniform_real< double > UniformRealDist
Definition: Rand.hh:37
boost::uniform_int< int > UniformIntDist
Definition: Rand.hh:43
boost::variate_generator< GeneratorType &, UniformRealDist > URealGen
Definition: Rand.hh:47
boost::variate_generator< GeneratorType &, NormalRealDist > NRealGen
Definition: Rand.hh:50
boost::variate_generator< GeneratorType &, UniformIntDist > UIntGen
Definition: Rand.hh:53