diff --git a/stat/distuv/pareto.go b/stat/distuv/pareto.go index b6aafae0..b29abacb 100644 --- a/stat/distuv/pareto.go +++ b/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. diff --git a/stat/distuv/pareto_test.go b/stat/distuv/pareto_test.go index e7bb8d1a..6bc8805a 100644 --- a/stat/distuv/pareto_test.go +++ b/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() + } +}