diff --git a/libraries/AP_Math/AP_Math.cpp b/libraries/AP_Math/AP_Math.cpp index 233959352ce..9f6c85ad99b 100644 --- a/libraries/AP_Math/AP_Math.cpp +++ b/libraries/AP_Math/AP_Math.cpp @@ -174,3 +174,17 @@ template int constrain_value(const int amt, const int low, const int high); template short constrain_value(const short amt, const short low, const short high); template float constrain_value(const float amt, const float low, const float high); template double constrain_value(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; +} + diff --git a/libraries/AP_Math/AP_Math.h b/libraries/AP_Math/AP_Math.h index 7ba1fe3fc47..686cd76b935 100644 --- a/libraries/AP_Math/AP_Math.h +++ b/libraries/AP_Math/AP_Math.h @@ -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); +