This commit is contained in:
Connor
2026-01-12 13:17:11 +08:00
parent 95851f8e69
commit 9600fc542c
132 changed files with 35734 additions and 5 deletions

28
pkg/utils/random.go Normal file
View File

@@ -0,0 +1,28 @@
package utils
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func GenerateVerificationCode(length int) string {
digits := "0123456789"
code := make([]byte, length)
for i := range code {
code[i] = digits[rand.Intn(len(digits))]
}
return string(code)
}
func GenerateRandomString(length int) string {
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
result := make([]byte, length)
for i := range result {
result[i] = chars[rand.Intn(len(chars))]
}
return string(result)
}