diff --git a/app/dns/server/nameserver.go b/app/dns/server/nameserver.go index 067d7a722..e413472ac 100644 --- a/app/dns/server/nameserver.go +++ b/app/dns/server/nameserver.go @@ -84,7 +84,7 @@ func (v *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 { } for { - id = dice.RandomUint16() + id = dice.RollUint16() if _, found := v.requests[id]; found { continue } diff --git a/common/dice/dice.go b/common/dice/dice.go index 8ffc1d28a..014f4c0de 100644 --- a/common/dice/dice.go +++ b/common/dice/dice.go @@ -15,8 +15,8 @@ func Roll(n int) int { return rand.Intn(n) } -// RandomUint16 returns a random uint16 value. -func RandomUint16() uint16 { +// RollUint16 returns a random uint16 value. +func RollUint16() uint16 { return uint16(rand.Intn(65536)) } diff --git a/transport/internet/headers/srtp/srtp.go b/transport/internet/headers/srtp/srtp.go index 0dffab54b..8a40d9c80 100644 --- a/transport/internet/headers/srtp/srtp.go +++ b/transport/internet/headers/srtp/srtp.go @@ -28,7 +28,7 @@ func (s *SRTP) Write(b []byte) (int, error) { func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) { return &SRTP{ header: 0xB5E8, - number: dice.RandomUint16(), + number: dice.RollUint16(), }, nil } diff --git a/transport/internet/headers/utp/utp.go b/transport/internet/headers/utp/utp.go index ec335eab2..4d8b8189d 100644 --- a/transport/internet/headers/utp/utp.go +++ b/transport/internet/headers/utp/utp.go @@ -31,7 +31,7 @@ func NewUTP(ctx context.Context, config interface{}) (interface{}, error) { return &UTP{ header: 1, extension: 0, - connectionId: dice.RandomUint16(), + connectionId: dice.RollUint16(), }, nil } diff --git a/transport/internet/headers/wechat/wechat.go b/transport/internet/headers/wechat/wechat.go index 52edb9f8a..ebc62571c 100644 --- a/transport/internet/headers/wechat/wechat.go +++ b/transport/internet/headers/wechat/wechat.go @@ -27,7 +27,7 @@ func (vc *VideoChat) Write(b []byte) (int, error) { func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) { return &VideoChat{ - sn: int(dice.RandomUint16()), + sn: int(dice.RollUint16()), }, nil } diff --git a/transport/internet/kcp/dialer.go b/transport/internet/kcp/dialer.go index f6d390f6b..16f9db0ef 100644 --- a/transport/internet/kcp/dialer.go +++ b/transport/internet/kcp/dialer.go @@ -18,7 +18,7 @@ import ( ) var ( - globalConv = uint32(dice.RandomUint16()) + globalConv = uint32(dice.RollUint16()) ) type ClientConnection struct { diff --git a/v2ray_test.go b/v2ray_test.go index 70011eb1f..020231117 100644 --- a/v2ray_test.go +++ b/v2ray_test.go @@ -20,7 +20,7 @@ import ( func TestV2RayClose(t *testing.T) { assert := assert.On(t) - port := v2net.Port(dice.RandomUint16()) + port := v2net.Port(dice.RollUint16()) config := &Config{ Inbound: []*proxyman.InboundHandlerConfig{ {