summaryrefslogtreecommitdiffstats
path: root/libgo/go/math/rand/rand_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/math/rand/rand_test.go')
-rw-r--r--libgo/go/math/rand/rand_test.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/libgo/go/math/rand/rand_test.go b/libgo/go/math/rand/rand_test.go
index bbd44e3f8b1..4d3abdb606c 100644
--- a/libgo/go/math/rand/rand_test.go
+++ b/libgo/go/math/rand/rand_test.go
@@ -57,16 +57,13 @@ func (this *statsResults) checkSimilarDistribution(expected *statsResults) error
func getStatsResults(samples []float64) *statsResults {
res := new(statsResults)
- var sum float64
- for i := range samples {
- sum += samples[i]
+ var sum, squaresum float64
+ for _, s := range samples {
+ sum += s
+ squaresum += s * s
}
res.mean = sum / float64(len(samples))
- var devsum float64
- for i := range samples {
- devsum += math.Pow(samples[i]-res.mean, 2)
- }
- res.stddev = math.Sqrt(devsum / float64(len(samples)))
+ res.stddev = math.Sqrt(squaresum/float64(len(samples)) - res.mean*res.mean)
return res
}
OpenPOWER on IntegriCloud