aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-12-13 16:34:10 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-12-17 11:39:14 +0100
commite3b5ea9797c9efc179d48eadf866561eb9cdebd8 (patch)
tree76d83aa5bcd06debc16017976b7605e73e713a09
parentb5b6142df447bafa795931b4e068085a92ca2f89 (diff)
prog: fix an unfortunate case of non-determinism
We used the math/rand global prng in biasedRand historically. Fix that.
-rw-r--r--prog/rand.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 839c6d1c3..b99399c9d 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -103,7 +103,7 @@ func (r *randGen) randRangeInt(begin uint64, end uint64) uint64 {
// probability of n-1 is k times higher than probability of 0.
func (r *randGen) biasedRand(n, k int) int {
nf, kf := float64(n), float64(k)
- rf := nf * (kf/2 + 1) * rand.Float64()
+ rf := nf * (kf/2 + 1) * r.Float64()
bf := (-1 + math.Sqrt(1+2*kf*rf/nf)) * nf / kf
return int(bf)
}