diff --git a/include/gen_utils.h b/include/gen_utils.h index 86b99cdf8..3b2f0384a 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -15,7 +15,7 @@ static unsigned int l_near_pow_2 (unsigned int n) { #ifndef def_fastrand inline int fastrand() { g_seed = (214013*g_seed+2531011); - return (g_seed>>16); + return (g_seed>>16)&0x7FFF; } #define def_fastrand #endif diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 14032de9f..4ef1d34e6 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1147,7 +1147,12 @@ MySrvC *MyHGC::get_random_MySrvC() { return NULL; // if we reach here, we couldn't find any target } - unsigned int k=fastrand()%New_sum; + unsigned int k; + if (New_sum > 32768) { + k=rand()%New_sum; + } else { + k=fastrand()%New_sum; + } k++; New_sum=0; @@ -1184,7 +1189,11 @@ MySQL_Connection * MySrvConnList::get_random_MyConn() { unsigned int i; unsigned int l=conns_length(); if (l) { - i=fastrand()%l; + if (l>32768) { + i=rand()%l; + } else { + i=fastrand()%l; + } conn=(MySQL_Connection *)conns->remove_index_fast(i); proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL Connection %p, server %s:%d\n", conn, conn->parent->address, conn->parent->port); return conn;