randString generates random names and prepends them with a known prefix.
(n int, src rand.Source, prefix string)
| 632 | |
| 633 | // randString generates random names and prepends them with a known prefix. |
| 634 | func randString(n int, src rand.Source, prefix string) string { |
| 635 | b := make([]byte, n) |
| 636 | // A rand.Int63() generates 63 random bits, enough for letterIdxMax letters! |
| 637 | for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { |
| 638 | if remain == 0 { |
| 639 | cache, remain = src.Int63(), letterIdxMax |
| 640 | } |
| 641 | if idx := int(cache & letterIdxMask); idx < len(letterBytes) { |
| 642 | b[i] = letterBytes[idx] |
| 643 | i-- |
| 644 | } |
| 645 | cache >>= letterIdxBits |
| 646 | remain-- |
| 647 | } |
| 648 | return prefix + string(b[0:30-len(prefix)]) |
| 649 | } |
| 650 | |
| 651 | // IsNetworkOrHostDown - if there was a network error or if the host is down. |
| 652 | // expectTimeouts indicates that *context* timeouts are expected and does not |