Skip to content

随机字符串

bash
package main

import (
  "encoding/hex"
  "fmt"
  "math/rand"
  "strconv"
  "time"
)


func main() {
  rand.Seed(time.Now().UnixNano())  //初始化种子
  b := make([]byte, 6)              //随机生成字符数组
  rand.Read(b)                      //整合
  rand_str := hex.EncodeToString(b) //转换为string
  fmt.Printf("%s", rand_str)        //打印
}