Files
stat_center/common/gencode/generate.go
T
2026-05-20 16:13:58 +08:00

41 lines
592 B
Go

package gencode
import (
"math/rand"
"time"
)
/**
* 生成邀请码
*/
var (
//所有的字符
ALL_CHARS = []string{
"1", "2", "3", "4", "5",
"6", "7", "8", "9", "A",
"B", "C", "D", "E", "F",
"G", "H", "J", "K",
"L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U",
"V", "W", "X", "Y", "Z"}
aLen = len(ALL_CHARS)
)
const (
//默认长度
DEFAULT_LEN = 6
)
func init() {
rand.Seed(time.Now().Unix())
}
// 生成指定长度的码
func CodeGenerate(len int) (code string) {
for i := 0; i < len; i++ {
index := rand.Intn(aLen)
code += ALL_CHARS[index]
}
return
}