16 Star 69 Fork 55

ShirDon-廖显东/Go语言高级开发与实战-随书代码

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
1.2.4-rand1.go 933 Bytes
Copy Edit Raw Blame History
ShirDon-廖显东 authored 2021-12-28 09:45 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 知乎:https://www.zhihu.com/people/shirdonl
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
//获取6位随机字符串
b := GetRandomString(6)
fmt.Println(b)
}
//获取随机字符串
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)
}
//330byd
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

Search