From ced2fb69b799410c4147677dc82633041b5008fb Mon Sep 17 00:00:00 2001
From: fatedier <fatedier@gmail.com>
Date: Thu, 22 Feb 2024 21:05:00 +0800
Subject: [PATCH] use math/rand/v2

---
 pkg/nathole/nathole.go   | 6 +++---
 pkg/util/util/util.go    | 4 ++--
 pkg/util/wait/backoff.go | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pkg/nathole/nathole.go b/pkg/nathole/nathole.go
index 065d0eb4..0210a250 100644
--- a/pkg/nathole/nathole.go
+++ b/pkg/nathole/nathole.go
@@ -17,7 +17,7 @@ package nathole
 import (
 	"context"
 	"fmt"
-	"math/rand"
+	"math/rand/v2"
 	"net"
 	"slices"
 	"strconv"
@@ -341,7 +341,7 @@ func sendSidMessage(
 		TransactionID: transactionID,
 		Sid:           sid,
 		Response:      false,
-		Nonce:         strings.Repeat("0", rand.Intn(20)),
+		Nonce:         strings.Repeat("0", rand.IntN(20)),
 	}
 	buf, err := EncodeMessage(m, key)
 	if err != nil {
@@ -398,7 +398,7 @@ func sendSidMessageToRandomPorts(
 	used := sets.New[int]()
 	getUnusedPort := func() int {
 		for i := 0; i < 10; i++ {
-			port := rand.Intn(65535-1024) + 1024
+			port := rand.IntN(65535-1024) + 1024
 			if !used.Has(port) {
 				used.Insert(port)
 				return port
diff --git a/pkg/util/util/util.go b/pkg/util/util/util.go
index c7fd9971..7758054d 100644
--- a/pkg/util/util/util.go
+++ b/pkg/util/util/util.go
@@ -20,7 +20,7 @@ import (
 	"crypto/subtle"
 	"encoding/hex"
 	"fmt"
-	mathrand "math/rand"
+	mathrand "math/rand/v2"
 	"net"
 	"strconv"
 	"strings"
@@ -124,7 +124,7 @@ func RandomSleep(duration time.Duration, minRatio, maxRatio float64) time.Durati
 	if max <= min {
 		n = min
 	} else {
-		n = mathrand.Int63n(max-min) + min
+		n = mathrand.Int64N(max-min) + min
 	}
 	d := duration * time.Duration(n) / time.Duration(1000)
 	time.Sleep(d)
diff --git a/pkg/util/wait/backoff.go b/pkg/util/wait/backoff.go
index 16d9dd6a..4d01ace3 100644
--- a/pkg/util/wait/backoff.go
+++ b/pkg/util/wait/backoff.go
@@ -15,7 +15,7 @@
 package wait
 
 import (
-	"math/rand"
+	"math/rand/v2"
 	"time"
 
 	"github.com/fatedier/frp/pkg/util/util"