diff --git a/etk/tool.cpp b/etk/tool.cpp index dc1525a..1e1c7d0 100644 --- a/etk/tool.cpp +++ b/etk/tool.cpp @@ -14,13 +14,20 @@ #include #include -float etk::tool::frand(float _a, float _b) +double etk::tool::frand(double _a, double _b) { - return ( rand()/(float)RAND_MAX ) * (_b-_a) + _a; + return (float)(( (double)rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a); } - int32_t etk::tool::irand(int32_t _a, int32_t _b) { - return (int32_t)(( rand()/(float)RAND_MAX ) * ((float)_b-(float)_a) + (float)_a); + return (int32_t)(( rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a); +} + +void etk::tool::resetRandom(void) { + srand(time(NULL)); +} + +void etk::tool::randSeek(int32_t _val) { + srand(_val); } diff --git a/etk/tool.h b/etk/tool.h index 7de11c0..049d1b3 100644 --- a/etk/tool.h +++ b/etk/tool.h @@ -13,8 +13,24 @@ namespace etk { namespace tool { - float frand(float _a, float _b); + /** + * @brief Get a random value in a specific range. + * @param[in] _a Lower value of the random. + * @param[in] _b Bigger value of the random. + * @return Random Value between [_a and _b] + */ + double frand(double _a, double _b); + //! @previous int32_t irand(int32_t _a, int32_t _b); + /** + * @brief Reset the random system with a random value (time). + */ + void resetRandom(void); + /** + * @brief Reset the random system with The specify value. + * @param[in] _val Seek value for the pseudo random system. + */ + void randSeek(int32_t _val); }; };