Seed random once in main
This commit is contained in:
parent
db97a88f94
commit
49deaae2ae
5
main.go
5
main.go
|
@ -4,9 +4,14 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hashicorp/consul/lib"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func init() {
|
||||
lib.SeedMathRand()
|
||||
}
|
||||
|
||||
func main() {
|
||||
os.Exit(Run(os.Args[1:]))
|
||||
}
|
||||
|
|
|
@ -249,11 +249,6 @@ func NewServer(config *Config) (*Server, error) {
|
|||
// Emit metrics
|
||||
go s.heartbeatStats()
|
||||
|
||||
// Seed the global random.
|
||||
if err := seedRandom(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Done
|
||||
return s, nil
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package nomad
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -11,8 +9,6 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
|
||||
crand "crypto/rand"
|
||||
|
||||
"github.com/hashicorp/serf/serf"
|
||||
)
|
||||
|
||||
|
@ -115,14 +111,3 @@ func maxUint64(a, b uint64) uint64 {
|
|||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// seedRandom seeds the global random variable using a cryptographically random
|
||||
// seed. It returns an error if determing the random seed fails.
|
||||
func seedRandom() error {
|
||||
n, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rand.Seed(n.Int64())
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue