diff options
author | Alex Flores <domain@me.com> | 2018-04-13 04:55:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-13 04:55:02 +0300 |
commit | fbfdd995dbb94254df558086197b671f96ea6c1f (patch) | |
tree | abe320dd12370c27b5162031cee97a51213213c1 | |
parent | 2bdf74d5a6998bcb57328ab1cb7fa4c0d0d8b6c5 (diff) | |
parent | bd207014a20b41554207fc9ac9457e61ab570429 (diff) |
Merge pull request #73 from audibleblink/master
patch for 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: |