all: use math/rand/v2 more

Updates #11058

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2024-06-05 14:37:31 -07:00
committed by Maisem Ali
parent d2d459d442
commit 4a8cb1d9f3
23 changed files with 43 additions and 66 deletions

View File

@@ -136,6 +136,7 @@ func (c *Conn) pickDERPFallback() int {
return pickDERPFallbackForTests()
}
// TODO: use math/rand/v2 here.
h := fnv.New64()
fmt.Fprintf(h, "%p/%d", c, processStartUnixNano) // arbitrary
return ids[rand.New(rand.NewSource(int64(h.Sum64()))).Intn(len(ids))]

View File

@@ -10,7 +10,7 @@ import (
"errors"
"fmt"
"math"
"math/rand"
"math/rand/v2"
"net"
"net/netip"
"reflect"
@@ -592,7 +592,7 @@ func (de *endpoint) addrForWireGuardSendLocked(now mono.Time) (udpAddr netip.Add
// Randomly select an address to use until we retrieve latency information
// and give it a short trustBestAddrUntil time so we avoid flapping between
// addresses while waiting on latency information to be populated.
udpAddr = candidates[rand.Intn(len(candidates))]
udpAddr = candidates[rand.IntN(len(candidates))]
}
de.bestAddr.AddrPort = udpAddr