2

golang随机字符串

 2 years ago
source link: https://studygolang.com/articles/28759?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

golang随机字符串

百里江山 · 2020-05-19 15:32:49 · 2043 次点击 · 预计阅读时间不到 1 分钟 · 大约8小时之前 开始浏览    
这是一个创建于 2020-05-19 15:32:49 的文章,其中的信息可能已经有所发展或是发生改变。
const char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func RandChar(size int) string {
    rand.NewSource(time.Now().UnixNano()) // 产生随机种子
    var s bytes.Buffer
    for i := 0; i < size; i ++ {
        s.WriteByte(char[rand.Int63() % int64(len(char))])
    }
    return s.String()
}


有疑问加站长微信联系(非本文作者)

280

本文来自:简书

感谢作者:百里江山

查看原文:golang随机字符串

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:701969077


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK