diff options
Diffstat (limited to 'libgo/go/net/dnsclient.go')
-rw-r--r-- | libgo/go/net/dnsclient.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/libgo/go/net/dnsclient.go b/libgo/go/net/dnsclient.go index b5bb3a4..e9c7384 100644 --- a/libgo/go/net/dnsclient.go +++ b/libgo/go/net/dnsclient.go @@ -5,12 +5,25 @@ package net import ( - "math/rand" "sort" "golang.org/x/net/dns/dnsmessage" ) +// provided by runtime +func fastrand() uint32 + +func randInt() int { + x, y := fastrand(), fastrand() // 32-bit halves + u := uint(x)<<31 ^ uint(int32(y)) // full uint, even on 64-bit systems; avoid 32-bit shift on 32-bit systems + i := int(u >> 1) // clear sign bit, even on 32-bit systems + return i +} + +func randIntn(n int) int { + return randInt() % n +} + // reverseaddr returns the in-addr.arpa. or ip6.arpa. hostname of the IP // address addr suitable for rDNS (PTR) record lookup or an error if it fails // to parse the IP address. @@ -162,7 +175,7 @@ func (addrs byPriorityWeight) shuffleByWeight() { } for sum > 0 && len(addrs) > 1 { s := 0 - n := rand.Intn(sum) + n := randIntn(sum) for i := range addrs { s += int(addrs[i].Weight) if s > n { @@ -206,7 +219,7 @@ func (s byPref) Swap(i, j int) { s[i], s[j] = s[j], s[i] } // sort reorders MX records as specified in RFC 5321. func (s byPref) sort() { for i := range s { - j := rand.Intn(i + 1) + j := randIntn(i + 1) s[i], s[j] = s[j], s[i] } sort.Sort(s) |