golang随机生成大写字母和数字的组合

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010918487/article/details/83989414
// 随机生成置顶位数的大写字母和数字的组合
func  GetRandomString(l int) string {
	str := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	bytes := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < l; i++ {
		result = append(result, bytes[r.Intn(len(bytes))])
	}
	return string(result)
}

猜你喜欢

转载自blog.csdn.net/u010918487/article/details/83989414