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