stat/distuv: improve Pareto.Rand performance, also adding Pareto.Rand benchmark
MODIFY
stat/distuv/pareto.go
stat/distuv/pareto.go
@@ -104,7 +104,7 @@ func (p Pareto) Rand() float64 {
} else {
rnd = rand.New(p.Src).ExpFloat64()
}
- return math.Exp(math.Log(p.Xm) + 1/p.Alpha*rnd)
+ return p.Xm * math.Exp(rnd/p.Alpha)
}
// StdDev returns the standard deviation of the probability distribution.

MODIFY
stat/distuv/pareto_test.go
stat/distuv/pareto_test.go
@@ -204,3 +204,11 @@ func TestParetoNotExists(t *testing.T) {
t.Errorf("Expected standard deviation == +Inf for Alpha == 1, got %v", stdDev)
}
}
+
+func BenchmarkParetoRand(b *testing.B) {
+ src := rand.New(rand.NewSource(1))
+ p := Pareto{1, 1, src}
+ for i := 0; i < b.N; i++ {
+ p.Rand()
+ }
+}

stat/distuv: improve Pareto.Rand performance, also adding Pareto.Rand benchmark