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

@@ -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]
}
}