ChooseRandom picks a random payload size (in bytes) that follows the underlying weighted random distribution.
()
| 154 | // ChooseRandom picks a random payload size (in bytes) that follows the |
| 155 | // underlying weighted random distribution. |
| 156 | func (pc *PayloadCurve) ChooseRandom() int { |
| 157 | target := rand.Float64() |
| 158 | var seen float64 |
| 159 | for _, pcr := range pc.pcrs { |
| 160 | seen += pcr.weight |
| 161 | if seen >= target { |
| 162 | return pcr.chooseRandom() |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // This should never happen, but if it does, return a sane default. |
| 167 | return 1 |
| 168 | } |
| 169 | |
| 170 | // Hash returns a string uniquely identifying a payload curve file for feature |
| 171 | // matching purposes. |
no test coverage detected