diff options
author | Alex Flores <domain@me.com> | 2018-03-30 21:14:18 +0300 |
---|---|---|
committer | Alex Flores <domain@me.com> | 2018-04-13 04:35:23 +0300 |
commit | bd207014a20b41554207fc9ac9457e61ab570429 (patch) | |
tree | 4872ca62e7225829e84c8f0810d0f514c77245db | |
parent | c38374ab5b21464b6a5ee6137393b236faeceff0 (diff) |
patch for better random proxy selection
-rw-r--r-- | src/core.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -514,6 +514,19 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) { return SOCKET_ERROR; } +unsigned int get_rand_int(unsigned int range){ + static FILE *fp; + unsigned int randval; + if (!fp) { + fp = fopen("/dev/urandom", "r"); + } + if(fread(&randval, sizeof(randval), 1, fp)) { + return (randval % range); + } else { + srand((unsigned int)time(NULL)); + return (rand() % range); + } +} static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) { unsigned int i = 0, k = 0; @@ -522,10 +535,10 @@ static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int p return NULL; switch (how) { case RANDOMLY: - srand((unsigned int)time(NULL)); + do { k++; - i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0)); + i = 0 + get_rand_int(proxy_count); } while(pd[i].ps != PLAY_STATE && k < proxy_count * 100); break; case FIFOLY: |