Rand.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 #ifndef IGNITION_MATH_RAND_HH_
18 #define IGNITION_MATH_RAND_HH_
19 
20 #include <random>
21 #include <cmath>
22 #include <cstdint>
23 #include <memory>
24 #include <ignition/math/Helpers.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
32  typedef std::mt19937 GeneratorType;
35  typedef std::uniform_real_distribution<double> UniformRealDist;
38  typedef std::normal_distribution<double> NormalRealDist;
41  typedef std::uniform_int_distribution<int32_t> UniformIntDist;
42 
46  {
50  public: static void Seed(unsigned int _seed);
51 
55  public: static unsigned int Seed();
56 
60  public: static double DblUniform(double _min = 0, double _max = 1);
61 
65  public: static double DblNormal(double _mean = 0, double _sigma = 1);
66 
70  public: static int32_t IntUniform(int _min, int _max);
71 
75  public: static int32_t IntNormal(int _mean, int _sigma);
76 
77 #ifdef _WIN32
78 // Disable warning C4251 which is triggered by
79 // std::unique_ptr
80 #pragma warning(push)
81 #pragma warning(disable: 4251)
82 #endif
83  private: static std::unique_ptr<GeneratorType> randGenerator;
85 #ifdef _WIN32
86 #pragma warning(pop)
87 #endif
88 
90  private: static uint32_t seed;
91  };
92  }
93 }
94 #endif
std::uniform_int_distribution< int32_t > UniformIntDist
Definition: Rand.hh:41
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:201
Random number generator class.
Definition: Rand.hh:45
std::mt19937 GeneratorType
Definition: Rand.hh:32
std::normal_distribution< double > NormalRealDist
Definition: Rand.hh:38
std::uniform_real_distribution< double > UniformRealDist
Definition: Rand.hh:35
Definition: AffineException.hh:30