AP_Math: added get_random16()

This commit is contained in:
Andrew Tridgell 2016-11-17 16:23:11 +11:00
parent cd57422eed
commit a8d10e8c2c
2 changed files with 18 additions and 0 deletions

View File

@ -174,3 +174,17 @@ template int constrain_value<int>(const int amt, const int low, const int high);
template short constrain_value<short>(const short amt, const short low, const short high);
template float constrain_value<float>(const float amt, const float low, const float high);
template double constrain_value<double>(const double amt, const double low, const double high);
/*
simple 16 bit random number generator
*/
uint16_t get_random16(void)
{
static uint32_t m_z = 1234;
static uint32_t m_w = 76542;
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return ((m_z << 16) + m_w) & 0xFFFF;
}

View File

@ -212,3 +212,7 @@ inline uint32_t usec_to_hz(uint32_t usec)
float linear_interpolate(float low_output, float high_output,
float var_value,
float var_low, float var_high);
/* simple 16 bit random number generator */
uint16_t get_random16(void);