DART  6.10.1
Random.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_MATH_RANDOM_HPP_
34 #define DART_MATH_RANDOM_HPP_
35 
36 #include <random>
37 
38 #include <Eigen/Core>
39 
40 namespace dart {
41 namespace math {
42 
43 class Random final
44 {
45 public:
46  using GeneratorType = std::mt19937;
47 
48  template <typename FloatType>
49  using UniformRealDist = std::uniform_real_distribution<FloatType>;
50 
51  template <typename IntType>
52  using UniformIntDist = std::uniform_int_distribution<IntType>;
53 
54  template <typename FloatType>
55  using NormalRealDist = std::normal_distribution<FloatType>;
56 
58  static GeneratorType& getGenerator();
59 
65  static void setSeed(unsigned int seed);
66 
71  static unsigned int generateSeed(bool applyGeneratedSeed = false);
72 
74  static unsigned int getSeed();
75 
123  template <typename S>
124  static S uniform(S min, S max);
125 
148  template <typename FixedSizeT>
149  static FixedSizeT uniform(
150  typename FixedSizeT::Scalar min, typename FixedSizeT::Scalar max);
151 
167  template <typename DynamicSizeVectorT>
168  static DynamicSizeVectorT uniform(
169  int size,
170  typename DynamicSizeVectorT::Scalar min,
171  typename DynamicSizeVectorT::Scalar max);
172 
184  template <typename DynamicSizeMatrixT>
185  static DynamicSizeMatrixT uniform(
186  int rows,
187  int cols,
188  typename DynamicSizeMatrixT::Scalar min,
189  typename DynamicSizeMatrixT::Scalar max);
190 
212  template <typename S>
213  static S normal(S mean, S sigma);
214 
215 private:
217  static unsigned int& getSeedMutable();
218 };
219 
220 } // namespace math
221 } // namespace dart
222 
224 
225 #endif // DART_MATH_RANDOM_HPP_
Definition: Random.hpp:44
std::uniform_int_distribution< IntType > UniformIntDist
Definition: Random.hpp:52
std::normal_distribution< FloatType > NormalRealDist
Definition: Random.hpp:55
std::uniform_real_distribution< FloatType > UniformRealDist
Definition: Random.hpp:49
static S normal(S mean, S sigma)
Returns a random number from a normal distribution.
Definition: Random-impl.hpp:454
static void setSeed(unsigned int seed)
Sets the seed value.
Definition: Random.cpp:46
static unsigned int getSeed()
Definition: Random.cpp:63
std::mt19937 GeneratorType
Definition: Random.hpp:46
static unsigned int generateSeed(bool applyGeneratedSeed=false)
Generates a seed value using the default random device.
Definition: Random.cpp:54
static unsigned int & getSeedMutable()
Definition: Random.cpp:69
static GeneratorType & getGenerator()
Returns a mutable reference to the random generator.
Definition: Random.cpp:39
static S uniform(S min, S max)
Returns a random number from an uniform distribution.
Definition: Random-impl.hpp:413
Definition: BulletCollisionDetector.cpp:65