package rand import ( crand "crypto/rand" "math/big" ) const base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // Base62 returns a cryptographically random base62 string of length n. func Base62(n int) (string, error) { out := make([]byte, n) for i := range out { idx, err := crand.Int(crand.Reader, big.NewInt(int64(len(base62)))) if err != nil { return "", err } out[i] = base62[idx.Int64()] } return string(out), nil }