mirror of
https://github.com/status-im/consul.git
synced 2025-02-16 15:47:21 +00:00
Always seed math/rand on consul startup
Required for jitter calcs. This could be done in consul/agent, but this makes it clear it is done only once process-wide.
This commit is contained in:
parent
7af6a94edb
commit
4382c1f7aa
18
lib/rand.go
Normal file
18
lib/rand.go
Normal file
@ -0,0 +1,18 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// SeedMathRand provides weak, but guaranteed seeding, which is better than
|
||||
// running with Go's default seed of 1. A call to SeedMathRand() is expected
|
||||
// to be called via init(), but never a second time.
|
||||
func SeedMathRand() {
|
||||
once.Do(func() { rand.Seed(time.Now().UTC().UnixNano()) })
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user