Actin®  Version 5.2.0
Software for Robotics Simulation and Control
ecRandom.h
Go to the documentation of this file.
1 #ifndef ecRandom_H_
2 #define ecRandom_H_
3 //------------------------------------------------------------------------------
4 // Copyright (c) 2007-2013 Energid Technologies. All rights reserved.
5 //
12 //
13 //------------------------------------------------------------------------------
14 #include "ecConfig.h" // Required to be first header.
15 #include "ecMacros.h"
16 #include "ecMath.h"
17 #include "ecOrientation.h"
18 #include "ecVector.h"
19 
20 #include <boost/random.hpp>
21 
22 #ifdef EC_HAS_boost_thread
23  #include <boost/thread/tss.hpp>
24 #else
25  #include <boost/scoped_ptr.hpp>
26 #endif
27 
32 typedef boost::mt19937 EcRandomNumberGeneratorType;
33 
35 {
36 public:
38  static EcRandomNumberGeneratorType* randomNumberGenerator
39  (
40  );
41 
43  static void seed
44  (
45  EcU32 seedNumber=0
46  );
47 
49 
54  static EcInt32 uniformIntRandom
55  (
56  EcInt32 lowerBound = 0,
57  EcInt32 upperBound = 99
58  );
59 
61 
67  static EcInt32Vector uniformIntRandoms
68  (
69  EcInt32 lowerBound,
70  EcInt32 upperBound,
71  EcU32 count
72  );
73 
75 
80  static EcReal uniformRealRandom
81  (
82  EcReal lowerBound = 0.0,
83  EcReal upperBound = 1.0
84  );
85 
87 
93  static EcRealVector uniformRealRandoms
94  (
95  EcReal lowerBound,
96  EcReal upperBound,
97  EcU32 count
98  );
99 
101 
106  static EcReal normalRandom
107  (
108  EcReal mean = 0.0,
109  EcReal sigma = 1.0
110  );
111 
113 
119  static EcRealVector normalRandoms
120  (
121  EcReal mean,
122  EcReal sigma,
123  EcU32 count
124  );
125 
127 
133  template <class VectorType>
134  static void normalRandoms
135  (
136  const VectorType& means,
137  const VectorType& sigmas,
138  VectorType& results,
139  EcReal defaultSigma=1.0
140  )
141  {
142  EcSizeT size = means.size();
143  // resize if necessary
144  results.resize(size);
145 
146  EcSizeT loops = EcMath::minimum<EcSizeT>(size, sigmas.size());
147  for (EcSizeT ii = 0; ii<loops; ++ii)
148  {
149  results[ii]=normalRandom(means[ii], sigmas[ii]);
150  }
151 
152  // if we don't have enough one sigmas
153  if(loops<size)
154  {
155  // use 1 as the default value
156  for (EcSizeT ii = loops; ii<size; ++ii)
157  {
158  results[ii]=normalRandom(means[ii], defaultSigma);
159  }
160  }
161  }
162 
164  static EcOrientation randomOrientation
165  (
166  );
167 
169 
173  static std::vector< EcOrientation > randomOrientations
174  (
175  EcU32 count
176  );
177 
179  static EcVector randomUnitVector
180  (
181  );
182 
184 
188  static std::vector< EcVector > randomUnitVectors
189  (
190  EcU32 count
191  );
192 
193 protected:
194 
195 #ifdef EC_HAS_boost_thread
196  static boost::thread_specific_ptr<EcRandomNumberGeneratorType> m_theRandomNumberGenerator;
199 #else
200  static boost::scoped_ptr<EcRandomNumberGeneratorType> m_theRandomNumberGenerator;
201 #endif
202 };
203 
204 #endif // ecRandom_H_
boost::uint32_t EcU32
32-bit unsigned integer
Definition: ecTypes.h:53
Description of a 3D rotation.
Definition: ecOrientation.h:25
Specify some global configuration parameters and values.
std::vector< EcInt32 > EcInt32Vector
a general 32-bit signed integer vector
Definition: ecTypes.h:177
std::size_t EcSizeT
unsigned integer type used to represent indices and the sizes of containers
Definition: ecTypes.h:129
boost::mt19937 EcRandomNumberGeneratorType
Definition: ecRandom.h:32
#define EC_STABLE_FOUNDCORE_DECL
foundCore directory
Definition: ecConfig.h:147
A utility class to generate random numbers.
Definition: ecRandom.h:34
boost::int32_t EcInt32
32-bit signed integer
Definition: ecTypes.h:56
std::vector< EcReal > EcRealVector
a general floating-point vector
Definition: ecTypes.h:168
EcF64 EcReal
Alias for 64-bit float.
Definition: ecTypes.h:30
Macros and C-style general functions.
A three-element vector.
Definition: ecVector.h:20
Created by Energid Technologies www.energid.com
Copyright © 2016 Energid. All trademarks mentioned in this document are property of their respective owners.