[DEV] add random set seek element
This commit is contained in:
parent
7f26881c3e
commit
89d9bc87ad
15
etk/tool.cpp
15
etk/tool.cpp
@ -14,13 +14,20 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
18
etk/tool.h
18
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);
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user