package util import ( "math/rand" "time" "unsafe" ) var r *rand.Rand func init() { r = rand.New(rand.NewSource(time.Now().Unix())) } func Str2bytes(s string) []byte { x := (*[2]uintptr)(unsafe.Pointer(&s)) h := [3]uintptr{x[0], x[1], x[1]} return *(*[]byte)(unsafe.Pointer(&h)) } func Bytes2str(b []byte) string { return *(*string)(unsafe.Pointer(&b)) } // RandString 生成随机字符串 func RandString(len int) string { bytes := make([]byte, len) for i := 0; i < len; i++ { b := r.Intn(26) + 65 bytes[i] = byte(b) } return string(bytes) }