Mercurial > gemma
diff pkg/common/random.go @ 3646:810b28f59b8b single-beam
Generate random points for second mesh.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 12 Jun 2019 17:30:20 +0200 |
parents | 6a021108410b |
children | 01ce3ba9b0d0 |
line wrap: on
line diff
--- a/pkg/common/random.go Wed Jun 12 12:57:14 2019 +0200 +++ b/pkg/common/random.go Wed Jun 12 17:30:20 2019 +0200 @@ -19,6 +19,8 @@ "io" "log" "math/big" + mrand "math/rand" + "time" ) // GenerateRandomKey generates a cryptographically secure random key @@ -64,3 +66,12 @@ out[0] = special[0] return string(out) } + +func Random(low, high float64) func() float64 { + if low > high { + low, high = high, low + } + rnd := mrand.New(mrand.NewSource(time.Now().Unix())) + m := high - low + return func() float64 { return rnd.Float64()*m + low } +}