chore: use fastrand to replace math/rand

This commit is contained in:
wwqgtxx
2023-03-06 18:10:14 +08:00
parent ad6336231c
commit 6a97ab9ecb
26 changed files with 109 additions and 111 deletions

View File

@ -6,19 +6,19 @@ import (
"context"
"crypto/tls"
"errors"
"math/rand"
"net"
"runtime"
"sync"
"sync/atomic"
"time"
"github.com/metacubex/quic-go"
N "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/common/pool"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
"github.com/metacubex/quic-go"
"github.com/zhangyunhao116/fastrand"
)
var (
@ -352,7 +352,7 @@ func (t *clientImpl) ListenPacketWithDialer(ctx context.Context, metadata *C.Met
pipe1, pipe2 := net.Pipe()
var connId uint32
for {
connId = rand.Uint32()
connId = fastrand.Uint32()
_, loaded := t.udpInputMap.LoadOrStore(connId, pipe1)
if !loaded {
break

View File

@ -5,11 +5,11 @@ package congestion
import (
"fmt"
"math"
"math/rand"
"net"
"time"
"github.com/metacubex/quic-go/congestion"
"github.com/zhangyunhao116/fastrand"
)
const (
@ -780,7 +780,7 @@ func (b *bbrSender) EnterProbeBandwidthMode(now time.Time) {
// Pick a random offset for the gain cycle out of {0, 2..7} range. 1 is
// excluded because in that case increased gain and decreased gain would not
// follow each other.
b.cycleCurrentOffset = rand.Int() % (GainCycleLength - 1)
b.cycleCurrentOffset = fastrand.Int() % (GainCycleLength - 1)
if b.cycleCurrentOffset >= 1 {
b.cycleCurrentOffset += 1
}