Skip to content

Commit

Permalink
Merge pull request #3020 from nexbridge/temp
Browse files Browse the repository at this point in the history
Fix bug in weight-based sort
  • Loading branch information
bogdan-iancu committed Mar 16, 2023
2 parents 4fe6572 + c7f1892 commit 48c051f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/drouting/drouting.c
Original file line number Diff line number Diff line change
Expand Up @@ -2913,11 +2913,11 @@ static int weight_based_sort(pgw_list_t *pgwl, int size, unsigned short *idx)
}
if (weight_sum) {
/* randomly select number */
rand_no = (unsigned int)(weight_sum*((float)rand()/(float)RAND_MAX));
rand_no = (unsigned int)(weight_sum*((double)rand()/((double)RAND_MAX)));
LM_DBG("random number is %d\n",rand_no);
/* select the element */
for( i=first ; i<size ; i++ )
if (running_sum[i]>rand_no) break;
if (running_sum[i]>=rand_no) break;
if (i==size) {
LM_CRIT("bug in weight sort, first=%u, size=%u, rand_no=%u, total weight=%u\n",
first, size, rand_no, weight_sum);
Expand All @@ -2930,7 +2930,7 @@ static int weight_based_sort(pgw_list_t *pgwl, int size, unsigned short *idx)
}
} else {
/* randomly select index */
// i = (unsigned int)((size-first)*((float)rand()/RAND_MAX));
// i = (unsigned int)((size-first)*((double)rand()/((double)RAND_MAX)));
i = first;
}
LM_DBG("selecting element %d with weight %d\n",
Expand Down

0 comments on commit 48c051f

Please sign in to comment.