From a0aabf2391ead23bc6831b74457168a1091c5b0d Mon Sep 17 00:00:00 2001 From: 9seconds Date: Tue, 17 Feb 2026 23:43:48 +0100 Subject: [PATCH] Switch to rand/v2 --- events/event_stream.go | 2 +- mtglib/internal/faketls/conn.go | 4 ++-- mtglib/internal/faketls/conn_test.go | 4 ++-- mtglib/internal/faketls/welcome.go | 4 ++-- mtglib/internal/faketls/welcome_test.go | 2 +- network/load_balanced_socks5.go | 4 ++-- network/network.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/events/event_stream.go b/events/event_stream.go index dede8b0..b71db4c 100644 --- a/events/event_stream.go +++ b/events/event_stream.go @@ -2,7 +2,7 @@ package events import ( "context" - "math/rand" + "math/rand/v2" "runtime" "github.com/9seconds/mtg/v2/mtglib" diff --git a/mtglib/internal/faketls/conn.go b/mtglib/internal/faketls/conn.go index f88771c..85acee2 100644 --- a/mtglib/internal/faketls/conn.go +++ b/mtglib/internal/faketls/conn.go @@ -3,7 +3,7 @@ package faketls import ( "bytes" "fmt" - "math/rand" + "math/rand/v2" "github.com/9seconds/mtg/v2/essentials" "github.com/9seconds/mtg/v2/mtglib/internal/faketls/record" @@ -53,7 +53,7 @@ func (c *Conn) Write(p []byte) (int, error) { lenP := len(p) for len(p) > 0 { - chunkSize := rand.Intn(record.TLSMaxRecordSize) + chunkSize := rand.IntN(record.TLSMaxRecordSize) if chunkSize > len(p) || chunkSize == 0 { chunkSize = len(p) } diff --git a/mtglib/internal/faketls/conn_test.go b/mtglib/internal/faketls/conn_test.go index c60dec9..29a8c0d 100644 --- a/mtglib/internal/faketls/conn_test.go +++ b/mtglib/internal/faketls/conn_test.go @@ -2,9 +2,9 @@ package faketls_test import ( "bytes" + "crypto/rand" "errors" "io" - "math/rand" "testing" "github.com/9seconds/mtg/v2/internal/testlib" @@ -123,7 +123,7 @@ func (suite *ConnTestSuite) TestWrite() { suite.connMock.On("Write", mock.Anything).Return(0, nil) dataToRec := make([]byte, record.TLSMaxRecordSize*2) - rand.Read(dataToRec) //nolint: staticcheck + rand.Read(dataToRec) //nolint: staticcheck, errcheck n, err := suite.c.Write(dataToRec) suite.NoError(err) diff --git a/mtglib/internal/faketls/welcome.go b/mtglib/internal/faketls/welcome.go index 8af46e4..0d91dac 100644 --- a/mtglib/internal/faketls/welcome.go +++ b/mtglib/internal/faketls/welcome.go @@ -6,7 +6,7 @@ import ( "crypto/sha256" "encoding/binary" "io" - mrand "math/rand" + mrand "math/rand/v2" "github.com/9seconds/mtg/v2/mtglib/internal/faketls/record" "golang.org/x/crypto/curve25519" @@ -36,7 +36,7 @@ func SendWelcomePacket(writer io.Writer, secret []byte, clientHello ClientHello) rec.Type = record.TypeApplicationData rec.Version = record.Version12 - if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil { + if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.IntN(3092))); err != nil { panic(err) } diff --git a/mtglib/internal/faketls/welcome_test.go b/mtglib/internal/faketls/welcome_test.go index 43ba033..e722007 100644 --- a/mtglib/internal/faketls/welcome_test.go +++ b/mtglib/internal/faketls/welcome_test.go @@ -3,8 +3,8 @@ package faketls_test import ( "bytes" "crypto/hmac" + "crypto/rand" "crypto/sha256" - "math/rand" "testing" "time" diff --git a/network/load_balanced_socks5.go b/network/load_balanced_socks5.go index f6d0a82..8aec387 100644 --- a/network/load_balanced_socks5.go +++ b/network/load_balanced_socks5.go @@ -3,7 +3,7 @@ package network import ( "context" "fmt" - "math/rand" + "math/rand/v2" "net/url" "github.com/9seconds/mtg/v2/essentials" @@ -19,7 +19,7 @@ func (l loadBalancedSocks5Dialer) Dial(network, address string) (essentials.Conn func (l loadBalancedSocks5Dialer) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) { length := len(l.dialers) - start := rand.Intn(length) + start := rand.IntN(length) moved := false for i := start; i != start || !moved; i = (i + 1) % length { diff --git a/network/network.go b/network/network.go index 3f68b11..5b536b4 100644 --- a/network/network.go +++ b/network/network.go @@ -3,7 +3,7 @@ package network import ( "context" "fmt" - "math/rand" + "math/rand/v2" "net" "net/http" "sync"