Random.h
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 
8 #ifndef NUKLEI_RANDOM_H
9 #define NUKLEI_RANDOM_H
10 
11 #include <nuklei/Definitions.h>
13 
14 namespace nuklei {
15 
16  /**
17  * @brief Implements random variate generators for various distributions.
18  */
19  class Random
20  {
21  public:
22  Random() {};
23  ~Random() {};
24 
25  /**
26  * @brief Seeds the random generators with @p s.
27  *
28  * This method will seed a built-in GSL generator, and the standard
29  * library's generator.
30  */
31  static void seed(unsigned s);
32 
33  /**
34  * @brief This function returns a double precision floating point number
35  * uniformly distributed in the range @f$ [0,1) @f$.
36  *
37  * The range includes 0.0 but excludes 1.0.
38  */
39  static double uniform();
40 
41  /**
42  * @brief This function returns a double precision floating point number
43  * uniformly distributed in the range @f$ [a,b) @f$.
44  *
45  * The range includes a but excludes b.
46  */
47  static double uniform(double a, double b);
48 
49  /**
50  * @brief This function returns a random integer from 0 to n-1 inclusive
51  *
52  * All integers in the range @f$ [0,n-1] @f$ are produced with equal
53  * probability.
54  */
55  static unsigned long int uniformInt(unsigned long int n);
56 
57  /**
58  * @brief This function returns a random variate from the triangle
59  * distribution of zero mean and base @p b.
60  *
61  * Use the transformation @f$ z = \mu + x @f$ on the numbers returned by
62  * this method to obtain a triangle distribution with mean @f$ \mu @f$.
63  */
64  static double triangle(double b);
65 
66  /**
67  * @brief This function returns a Gaussian random variate, with mean zero and
68  * standard deviation @p sigma.
69  *
70  * Use the transformation @f$ z = \mu + x @f$ on the numbers returned by
71  * this method to obtain a Gaussian distribution with mean @f$ \mu @f$.
72  */
73  static double gaussian(double sigma);
74 
75  /**
76  * @brief This function returns a random variate from the beta distribution.
77  */
78  static double beta(double a, double b);
79 
80  /**
81  * @brief This function returns a random direction vector @f$ v = (x,y) @f$
82  * in two dimensions.
83  *
84  * The vector is normalized such that @f$ |v|^2 = x^2 + y^2 = 1 @f$.
85  */
86  static Vector2 uniformDirection2d();
87 
88  /**
89  * @brief This function returns a random direction vector @f$ v = (x,y,z)
90  * @f$ in three dimensions.
91  *
92  * The vector is normalized such that @f$ |v|^2 = x^2 + y^2 + z^2 = 1 @f$.
93  */
94  static Vector3 uniformDirection3d();
95 
96  /**
97  * @brief This function returns rotation uniformly distributed on @f$ SO(3)
98  * @f$.
99  */
100  static Quaternion uniformQuaternion();
101 
102  static void printRandomState();
103 
104  /**
105  * @brief Used internally.
106  */
107  static bool init();
108  private:
109  static bool initialized_;
110  };
111 
112 }
113 
114 #endif
static double beta(double a, double b)
This function returns a random variate from the beta distribution.
Definition: Random.cpp:277
Public namespace.
Definition: Color.cpp:9
static double triangle(double b)
This function returns a random variate from the triangle distribution of zero mean and base b.
Definition: Random.cpp:229
static Vector2 uniformDirection2d()
This function returns a random direction vector in two dimensions.
Definition: Random.cpp:292
static unsigned long int uniformInt(unsigned long int n)
This function returns a random integer from 0 to n-1 inclusive.
Definition: Random.cpp:195
static void seed(unsigned s)
Seeds the random generators with s.
Definition: Random.cpp:135
static Quaternion uniformQuaternion()
This function returns rotation uniformly distributed on .
Definition: Random.cpp:347
static bool init()
Used internally.
Definition: Random.cpp:76
static double uniform()
This function returns a double precision floating point number uniformly distributed in the range .
Definition: Random.cpp:159
static Vector3 uniformDirection3d()
This function returns a random direction vector in three dimensions.
Definition: Random.cpp:320
static double gaussian(double sigma)
This function returns a Gaussian random variate, with mean zero and standard deviation sigma.
Definition: Random.cpp:253
Implements random variate generators for various distributions.
Definition: Random.h:19
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.