forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user