Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If records have weight, choose randomly based on weight #3

Closed
abh opened this issue Aug 24, 2012 · 0 comments
Closed

If records have weight, choose randomly based on weight #3

abh opened this issue Aug 24, 2012 · 0 comments

Comments

@abh
Copy link
Owner

abh commented Aug 24, 2012

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).

@abh abh closed this as completed in 7e73cbc Aug 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant