rcrowley / go-metrics

Go port of Coda Hale's Metrics library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExpDecaySample.Update - problem with rand.Float64() divider

LopatkinEvgeniy opened this issue · comments

There is a code:

func (s *ExpDecaySample) update(t time.Time, v int64) {
// ...

	s.values.Push(expDecaySample{
		k: math.Exp(t.Sub(s.t0).Seconds()*s.alpha) / rand.Float64(),
		v: v,
	})

// ...
{

If rand.Float64() will return zero then the "k" value will be Inf. So this value will never be dropped (until rescale). This will increase the error of the results. Maybe division by random number is not a good idea?