9 strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters
15 for i := 0; i < 8; i++ {
19 rand.Seed(int64(seed))
22 // Constructs an alphanumeric string of given length.
23 func RandStr(length int) string {
28 for i := 0; i < 10; i++ {
29 v := int(val & 0x3f) // rightmost 6 bits
30 if v >= 62 { // only 62 characters in strChars
34 chars = append(chars, strChars[v])
35 if len(chars) == length {
50 func RandBytes(n int) []byte {
52 for i := 0; i < n; i++ {
53 bs[i] = byte(rand.Intn(256))
58 // NOTE: This relies on the os's random number generator.
59 // For real security, we should salt that with some seed.
60 // See github.com/tendermint/go-crypto for a more secure reader.
61 func cRandBytes(numBytes int) []byte {
62 b := make([]byte, numBytes)
63 _, err := crand.Read(b)