switch from math/rand to math/rand/v2 (#5045)

* switch from math/rand to math/rand/v2

* switch away from golang.org/x/exp/rand
This commit is contained in:
Marten Seemann
2025-04-19 15:01:22 +08:00
committed by GitHub
parent c60438c528
commit 267cca773b
29 changed files with 168 additions and 162 deletions

View File

@@ -3,10 +3,11 @@ package self_test
import (
"bytes"
"context"
"crypto/rand"
"crypto/tls"
"fmt"
"io"
mrand "math/rand"
mrand "math/rand/v2"
"net"
"sync"
"sync/atomic"
@@ -189,7 +190,7 @@ func dropCallbackDropOneThird(direction quicproxy.Direction) quicproxy.DropCallb
var mx sync.Mutex
var incoming, outgoing int
return func(d quicproxy.Direction, _, _ net.Addr, _ []byte) bool {
drop := mrand.Int63n(int64(3)) == 0
drop := mrand.IntN(3) == 0
mx.Lock()
defer mx.Unlock()
@@ -274,10 +275,10 @@ func TestPostQuantumClientHello(t *testing.T) {
t.Cleanup(func() { wire.AdditionalTransportParametersClient = origAdditionalTransportParametersClient })
b := make([]byte, 2500) // the ClientHello will now span across 3 packets
mrand.New(mrand.NewSource(time.Now().UnixNano())).Read(b)
rand.Read(b)
wire.AdditionalTransportParametersClient = map[uint64][]byte{
// Avoid random collisions with the greased transport parameters.
uint64(27+31*(1000+mrand.Int63()/31)) % quicvarint.Max: b,
uint64(27+31*(1000+mrand.IntN(31))/31) % quicvarint.Max: b,
}
ln, proxyPort := startDropTestListenerAndProxy(t, 10*time.Millisecond, 20*time.Second, dropCallbackDropOneThird(quicproxy.DirectionIncoming), false, false)