| 98 | } |
| 99 | |
| 100 | int WeightedPicker::Pick(SimplePhilox* rnd) const { |
| 101 | if (total_weight() == 0) return -1; |
| 102 | |
| 103 | // using unbiased uniform distribution to avoid bias |
| 104 | // toward low elements resulting from a possible use |
| 105 | // of big weights. |
| 106 | return PickAt(UnbiasedUniform(rnd, total_weight())); |
| 107 | } |
| 108 | |
| 109 | int WeightedPicker::PickAt(int32 weight_index) const { |
| 110 | if (weight_index < 0 || weight_index >= total_weight()) return -1; |