mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
all: use math/rand/v2 more
Updates #11058 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -74,8 +74,7 @@ func getDigitalOceanResolver() string {
|
||||
// Randomly select one of the available resolvers so we don't overload
|
||||
// one of them by sending all traffic there.
|
||||
return digitalOceanResolver.Get(func() string {
|
||||
rn := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
return digitalOceanResolvers[rn.Intn(len(digitalOceanResolvers))]
|
||||
return digitalOceanResolvers[rand.IntN(len(digitalOceanResolvers))]
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
@@ -73,7 +73,7 @@ func (r *ReloadOpts[T]) intervalWithJitter() time.Duration {
|
||||
return tt
|
||||
}
|
||||
|
||||
jitter := time.Duration(rand.Intn(int(r.IntervalJitter)))
|
||||
jitter := rand.N(r.IntervalJitter)
|
||||
return tt + jitter
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
// Package slicesx contains some helpful generic slice functions.
|
||||
package slicesx
|
||||
|
||||
import "math/rand"
|
||||
import "math/rand/v2"
|
||||
|
||||
// Interleave combines two slices of the form [a, b, c] and [x, y, z] into a
|
||||
// slice with elements interleaved; i.e. [a, x, b, y, c, z].
|
||||
@@ -34,11 +34,11 @@ func Shuffle[S ~[]T, T any](s S) {
|
||||
n := len(s)
|
||||
i := n - 1
|
||||
for ; i > 1<<31-1-1; i-- {
|
||||
j := int(rand.Int63n(int64(i + 1)))
|
||||
j := int(rand.N(int64(i + 1)))
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
for ; i > 0; i-- {
|
||||
j := int(rand.Int31n(int32(i + 1)))
|
||||
j := int(rand.N(int32(i + 1)))
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user