diff options
-rw-r--r-- | src/math/functions.cc | 11 | ||||
-rw-r--r-- | src/math/functions.h | 39 |
2 files changed, 28 insertions, 22 deletions
diff --git a/src/math/functions.cc b/src/math/functions.cc index 7c95a79..ffbf453 100644 --- a/src/math/functions.cc +++ b/src/math/functions.cc @@ -5,23 +5,12 @@ */ #include "math/functions.h" -#include <stdlib.h> namespace math { const float DELTA = 10e-10; -float randomf(const float max) -{ - return ((float) rand() / (float) RAND_MAX) * max; -} - -unsigned randomi(const unsigned int max) -{ - return ((unsigned int)(rand() % max)); -} - float degrees180f(float angle) { float r = angle; diff --git a/src/math/functions.h b/src/math/functions.h index 8135392..44ec1fa 100644 --- a/src/math/functions.h +++ b/src/math/functions.h @@ -7,8 +7,7 @@ #ifndef __INCLUDED_MATH_FUNCTIONS_H__ #define __INCLUDED_MATH_FUNCTIONS_H__ -#include <math.h> - +#include <cmath> #include <cstdlib> #include <cmath> @@ -63,17 +62,35 @@ inline const long max(const long a, const long b) return (a > b ? a : b); } -/// returns a random float -/** The value returned will be in the interval [0-max] - * @param max the maximum value returned - **/ -float randomf(const float max = 1.0f); + /** + * @brief returns a random float + * The value returned will be in the interval [0-max] + * @param max the maximum value returned + * */ +inline float randomf(const float max = 1.0f) +{ + return ((float) rand() / (float) RAND_MAX) * max; +} + + /** + * @brief returns a random float + * The value returned will be in the interval [min-max] + * */ +inline float randomf(const float min, const float max) +{ + return (min + randomf(max - min)); +} -/// returns a random integer -/** The value returned will be in the interval [0-(max-1)] +/** + * @brief returns a random integer + * The value returned will be in the interval [0-(max-1)] * @param max the maximum value returned - **/ -unsigned int randomi(const unsigned int max); + * */ + +inline unsigned randomi(const unsigned int max) +{ + return ((unsigned int)(rand() % max)); +} /// return the sign of a float value float sgnf(float value); |