From ec8c3a8d02645ac32eb1a2cb6e005eccf7c72191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=83=E9=9A=A8=E7=B7=A3=E5=8B=95?= Date: Tue, 7 Oct 2025 23:33:33 +0800 Subject: [PATCH] New features: TG Telegram robot terminal [One-click configuration] and [Subscription conversion] --- util/common/random.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 util/common/random.go diff --git a/util/common/random.go b/util/common/random.go new file mode 100644 index 00000000..ccd35e91 --- /dev/null +++ b/util/common/random.go @@ -0,0 +1,18 @@ +package common + +import ( + "crypto/rand" + "math/big" +) + +// RandomInt 返回一个 0 .. max-1 之间的随机整数(使用 crypto/rand) +func RandomInt(max int) int { + if max <= 0 { + return 0 + } + n, err := rand.Int(rand.Reader, big.NewInt(int64(max))) + if err != nil { + return 0 + } + return int(n.Int64()) +}