mirror of
https://github.com/abh/geodns.git
synced 2026-04-27 03:45:53 +03:00
[GH-ISSUE #3] If records have weight, choose randomly based on weight #2
Labels
No labels
bug
bug
enhancement
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/geodns#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abh on GitHub (Aug 24, 2012).
Original GitHub issue: https://github.com/abh/geodns/issues/3
If records have weight configured, choose them randomly based on the weight. The perl implementation sorts the records by weight (descending), adds up the total weight and then generates a random number between 0 and then loops through the records until the accumulated weight is higher than the random number.
Stackoverflow suggests basically the same algorithm, though modifying the slice after each pick to avoid duplicates (the perl version tries doing that with brute-force).