forked from TrueCloudLab/frostfs-http-gw
*: fix all comment-related golint warnings
Some of this code is going to be moved to SDK library, so it's important. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
3173c70eb6
commit
df3c87af79
14 changed files with 88 additions and 4 deletions
|
@ -2,13 +2,17 @@ package connections
|
|||
|
||||
import "math/rand"
|
||||
|
||||
// See Vose's Alias Method (https://www.keithschwarz.com/darts-dice-coins/).
|
||||
// Sampler implements weighted random number generation using Vose's Alias
|
||||
// Method (https://www.keithschwarz.com/darts-dice-coins/).
|
||||
type Sampler struct {
|
||||
randomGenerator *rand.Rand
|
||||
probabilities []float64
|
||||
alias []int
|
||||
}
|
||||
|
||||
// NewSampler creates new Sampler with a given set of probabilities using
|
||||
// given source of randomness. Created Sampler will produce numbers from
|
||||
// 0 to len(probabilities).
|
||||
func NewSampler(probabilities []float64, source rand.Source) *Sampler {
|
||||
sampler := &Sampler{}
|
||||
var (
|
||||
|
@ -53,6 +57,7 @@ func NewSampler(probabilities []float64, source rand.Source) *Sampler {
|
|||
return sampler
|
||||
}
|
||||
|
||||
// Next returns the next (not so) random number from Sampler.
|
||||
func (g *Sampler) Next() int {
|
||||
n := len(g.alias)
|
||||
i := g.randomGenerator.Intn(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue