Skip to content

Commit 79f2b6a

Browse files
committed
fix(name): fix the name util
1 parent 40046df commit 79f2b6a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

utils/name/name.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66
)
77

8-
// 名字生成器
8+
//
99
var surnames = []string{
1010
"赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋",
1111
"沈", "韩", "杨", "朱", "秦", "尤", "许", "何", "吕", "施", "张", "孔", "曹", "严", "华", "金", "魏",
@@ -27,7 +27,8 @@ var surnames = []string{
2727
"太叔", "申屠", "公孙", "仲孙", "轩辕", "令狐", "徐离", "宇文", "长孙", "慕容", "司徒", "司空",
2828
}
2929

30-
var lastnames = []string{
30+
// 姓
31+
var lastNames = []string{
3132
"伟", "刚", "勇", "毅", "俊", "峰", "强", "军", "平", "保", "东", "文", "辉", "力", "明", "永", "健", "世", "广", "志", "义",
3233
"兴", "良", "海", "山", "仁", "波", "宁", "贵", "福", "生", "龙", "元", "全", "国", "胜", "学", "祥", "才", "发", "武", "新",
3334
"利", "清", "飞", "彬", "富", "顺", "信", "子", "杰", "涛", "昌", "成", "康", "星", "光", "天", "达", "安", "岩", "中", "茂",
@@ -47,19 +48,16 @@ var lastnames = []string{
4748
"宗", "曼", "紫", "逸", "贤", "蝶", "菡", "绿", "蓝", "儿", "翠", "烟", "小", "轩",
4849
}
4950

50-
var (
51-
lastnamesLength = len(lastnames)
52-
surnamesLength = len(surnames)
53-
source = rand.NewSource(time.Now().Unix())
54-
random = rand.New(source)
55-
)
51+
func init() {
52+
rand.Seed(time.Now().UnixNano())
53+
}
5654

5755
func getSurname() string {
58-
return surnames[random.Intn(surnamesLength-1)]
56+
return surnames[rand.Intn(len(surnames)-1)]
5957
}
6058

6159
func getLastName() string {
62-
return lastnames[random.Intn(lastnamesLength-1)]
60+
return lastNames[rand.Intn(len(lastNames)-1)]
6361
}
6462

6563
// GenerateUserName random generate one user name with specific length

0 commit comments

Comments
 (0)