aboutsummaryrefslogtreecommitdiff
path: root/src/net/dnsclient.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/dnsclient.go')
-rw-r--r--src/net/dnsclient.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go
index b5bb3a4d11..e9c73845d7 100644
--- a/src/net/dnsclient.go
+++ b/src/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)