AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Random.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_RANDOM_H
18#define AGX_RANDOM_H
19
20
21
22#include <agx/macros.h>
23#include <agx/Real.h>
24#include <agx/Integer.h>
25#include <random>
26
27namespace agx
28{
29 template<typename T, template<typename> class DistributionT, typename EngineT = std::mt19937>
31 {
32 public:
33
34
35 template < class Generator, class Dist >
37 public:
38 // generator interface
39 typedef typename Dist::result_type result_type;
40 typedef Generator engine_type;
41 typedef Generator engine_value_type;
42 typedef Dist distribution_type;
43
44 result_type operator() () { return D(G); }
45 result_type min() const { return D.min(); }
46 result_type max() const { return D.max(); }
47
48 // type-specific members
50 distribution_type D0) : G(G0), D(D0) {}
51 template < class ValT >
52 AGX_FORCE_INLINE result_type operator() (ValT value) { return D(G, value); }
53
55 {
56 return G;
57 }
58
59 const engine_value_type & engine() const
60 {
61 return G;
62 }
64 {
65 return D;
66 }
68 {
69 return D;
70 }
71
72 // exposition only:
73 private:
74 Generator G;
75 Dist D;
76 };
77
78
79
81
82 public:
84 RandomGenerator(T minValue, T maxValue);
86 RandomGenerator(agx::UInt32 seed, T minValue, T maxValue);
87
89 T rand();
91
93
95 const ImplementationT& impl() const;
96
97 private:
98 ImplementationT m_generator;
99 };
100
101
102
106
107
111
112
113
114
116
117 template<typename T, template<typename> class DistributionT, typename EngineT>
119 m_generator(EngineT(), DistributionT<T>())
120 {
121 }
122
123 template<typename T, template<typename> class DistributionT, typename EngineT>
125 m_generator(EngineT(), DistributionT<T>(minValue, maxValue))
126 {
127 }
128
129 template<typename T, template<typename> class DistributionT, typename EngineT>
131 m_generator(EngineT(), DistributionT<T>())
132 {
133 this->seed(seed);
134 }
135
136 template<typename T, template<typename> class DistributionT, typename EngineT>
138 m_generator(EngineT(), DistributionT<T>(minValue, maxValue))
139 {
140 this->seed(seed);
141 }
142
143 template<typename T, template<typename> class DistributionT, typename EngineT>
148
149 template<typename T, template<typename> class DistributionT, typename EngineT>
151 {
152 m_generator.engine().seed(seed);
153 m_generator.distribution().reset();
154 }
155
156 template<typename T, template<typename> class DistributionT, typename EngineT>
161
162
163 template<typename T, template<typename> class DistributionT, typename EngineT>
168
169 template<typename T, template<typename> class DistributionT, typename EngineT>
174}
175
176#endif /* AGX_RANDOM_H */
engine_value_type & engine()
Definition Random.h:54
const distribution_type & distribution() const
Definition Random.h:67
const engine_value_type & engine() const
Definition Random.h:59
distribution_type & distribution()
Definition Random.h:63
variate_generator(engine_type G0, distribution_type D0)
Definition Random.h:49
RandomGenerator(agx::UInt32 seed)
Definition Random.h:130
RandomGenerator(T minValue, T maxValue)
Definition Random.h:124
RandomGenerator(agx::UInt32 seed, T minValue, T maxValue)
Definition Random.h:137
ImplementationT & impl()
Definition Random.h:164
T rand()
Returns random number between minValue and maxValue (from constructor).
Definition Random.h:144
const ImplementationT & impl() const
Definition Random.h:170
void seed(agx::UInt32 seed)
Definition Random.h:150
variate_generator< EngineT, DistributionT< T > > ImplementationT
Definition Random.h:80
RandomGenerator()
Implementation.
Definition Random.h:118
#define AGX_FORCE_INLINE
Definition macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
RandomGenerator< agx::Real, std::uniform_real_distribution > UniformRealGenerator
Definition Random.h:103
uint32_t UInt32
Definition Integer.h:32
RandomGenerator< agx::Real32, std::uniform_real_distribution > UniformReal32Generator
Definition Random.h:104
RandomGenerator< agx::Int32, std::uniform_int_distribution > UniformInt32Generator
Definition Random.h:109
RandomGenerator< agx::Real64, std::uniform_real_distribution > UniformReal64Generator
Definition Random.h:105
RandomGenerator< agx::Int64, std::uniform_int_distribution > UniformInt64Generator
Definition Random.h:110
RandomGenerator< agx::Int, std::uniform_int_distribution > UniformIntGenerator
Definition Random.h:108