dns resolver: create rand seed at init time (#2007)

This commit is contained in:
lyuxuan 2018-04-26 15:10:23 -07:00 committed by GitHub
parent 66090d990b
commit 07709e8a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -50,7 +50,10 @@ const (
txtAttribute = "grpc_config="
)
var errMissingAddr = errors.New("missing address")
var (
errMissingAddr = errors.New("missing address")
randomGen = rand.New(rand.NewSource(time.Now().UnixNano()))
)
// NewBuilder creates a dnsBuilder which is used to factory DNS resolvers.
func NewBuilder() resolver.Builder {
@ -338,9 +341,7 @@ func chosenByPercentage(a *int) bool {
if a == nil {
return true
}
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
return r.Intn(100)+1 <= *a
return randomGen.Intn(100)+1 <= *a
}
func canaryingSC(js string) string {