randomString 生成随机字符串(使用 crypto/rand)
(n int)
| 568 | |
| 569 | // randomString 生成随机字符串(使用 crypto/rand) |
| 570 | func randomString(n int) string { |
| 571 | b := make([]byte, (n+1)/2) |
| 572 | if _, err := rand.Read(b); err != nil { |
| 573 | // fallback: 使用时间戳 |
| 574 | return time.Now().Format("150405.000000000")[:n] |
| 575 | } |
| 576 | return hex.EncodeToString(b)[:n] |
| 577 | } |