go语言的名字生成系统

import (
	"fmt"
	"math/rand"
	"time"
)

var (
	familiyNames = []string{"赵","钱","孙","李","周","吴","郑","王","冯","陈","褚","卫","蒋","沈","韩","杨","张","欧阳"}
	firstNames = []string{"金","木","水","火","土","春","夏","秋","冬","山","石","田","天","地","玄","黄","宇","宙","洪","荒"}
	//辈分
	generationNameMap = make(map[string][]string)
	names = make([]string,0)
)

func init() {
	generationNameMap["欧阳"] = []string{"宗","的","永","其","光"}
	for _,ln := range familiyNames{
		if ln != "欧阳"{
			generationNameMap[ln] = []string{"飞","前","茂","百","方","书","生","无","一","用"}
		}
	}
}

func GetRandomName() (name string){
	familiyName := familiyNames[GetRandomInt(0,len(familiyNames)-1)]
	middleName := generationNameMap[familiyName][GetRandomInt(0,len(generationNameMap[familiyName])-1)]
	firstName := firstNames[GetRandomInt(0,len(firstNames)-1)]
	return familiyName + middleName + firstName
}

//生成随机数
func GetRandomInt(start,end int) int{
	<-time.After(1 * time.Nanosecond)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	return start + r.Intn(end-start)
}

func main() {
	for i:=0;i<100 ;i++  {
		names = append(names,GetRandomName())
	}
	fmt.Println(names)

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值