comparison 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
comparison
equal deleted inserted replaced
3640:10471aa73ad8 3646:810b28f59b8b
17 "bytes" 17 "bytes"
18 "crypto/rand" 18 "crypto/rand"
19 "io" 19 "io"
20 "log" 20 "log"
21 "math/big" 21 "math/big"
22 mrand "math/rand"
23 "time"
22 ) 24 )
23 25
24 // GenerateRandomKey generates a cryptographically secure random key 26 // GenerateRandomKey generates a cryptographically secure random key
25 // of a given length. 27 // of a given length.
26 func GenerateRandomKey(length int) []byte { 28 func GenerateRandomKey(length int) []byte {
62 } 64 }
63 log.Println("warn: Your random generator may be broken.") 65 log.Println("warn: Your random generator may be broken.")
64 out[0] = special[0] 66 out[0] = special[0]
65 return string(out) 67 return string(out)
66 } 68 }
69
70 func Random(low, high float64) func() float64 {
71 if low > high {
72 low, high = high, low
73 }
74 rnd := mrand.New(mrand.NewSource(time.Now().Unix()))
75 m := high - low
76 return func() float64 { return rnd.Float64()*m + low }
77 }