25 lines
527 B
Go
25 lines
527 B
Go
package captcha
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// RandDigit 随机数
|
|
func RandDigit(max int) int {
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
return r.Intn(max)
|
|
}
|
|
|
|
// RandDigitRange 随机数范围
|
|
func RandDigitRange(max int, min int) int {
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
return r.Intn(max-min) + min
|
|
}
|
|
|
|
// RandChooseOne 数组随机选一个元素
|
|
func RandChooseOne[T any](reasons []T) T {
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
return reasons[r.Intn(len(reasons))]
|
|
}
|