Mercurial > gemma
diff pkg/common/random.go @ 3650:01ce3ba9b0d0 single-beam
Fixed generating of random points.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 13 Jun 2019 13:14:40 +0200 |
parents | 810b28f59b8b |
children | 8c5df0f3562e |
line wrap: on
line diff
--- a/pkg/common/random.go Wed Jun 12 17:30:20 2019 +0200 +++ b/pkg/common/random.go Thu Jun 13 13:14:40 2019 +0200 @@ -18,6 +18,7 @@ "crypto/rand" "io" "log" + "math" "math/big" mrand "math/rand" "time" @@ -71,7 +72,15 @@ if low > high { low, high = high, low } - rnd := mrand.New(mrand.NewSource(time.Now().Unix())) + + var seed int64 + if seedInt, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64)); err != nil { + log.Printf("warn: Generating good random seed failed: %v\n", err) + seed = time.Now().Unix() + } else { + seed = seedInt.Int64() + } + rnd := mrand.New(mrand.NewSource(seed)) m := high - low return func() float64 { return rnd.Float64()*m + low } }