Skip to content

Commit 1b60c84

Browse files
committed
better random proxy selection
1 parent c97f93a commit 1b60c84

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,29 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
529529
return SOCKET_ERROR;
530530
}
531531

532+
unsigned int get_rand_int(unsigned int range){
533+
static FILE *fp;
534+
unsigned int randval;
535+
if (!fp) {
536+
fp = fopen("/dev/urandom", "r");
537+
}
538+
if(fread(&randval, sizeof(randval), 1, fp)) {
539+
return (randval % range);
540+
} else {
541+
srand((unsigned int)time(NULL));
542+
return (rand() % range);
543+
}
544+
}
545+
532546
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
533547
unsigned int i = 0, k = 0;
534548
if(*offset >= proxy_count)
535549
return NULL;
536550
switch (how) {
537551
case RANDOMLY:
538-
srand(time(NULL));
539552
do {
540553
k++;
541-
i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0));
554+
i = 0 + get_rand_int(proxy_count);
542555
} while(pd[i].ps != PLAY_STATE && k < proxy_count * 100);
543556
break;
544557
case FIFOLY:

0 commit comments

Comments
 (0)