Seed random once in main

This commit is contained in:
Sean Chittenden 2016-05-03 00:28:23 -07:00
parent db97a88f94
commit 49deaae2ae
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
3 changed files with 5 additions and 20 deletions

View File

@ -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:]))
}

View File

@ -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
}

View File

@ -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
}