github.com/jfrazelle/docker@v1.1.2-0.20210712172922-bf78e25fe508/testutil/stringutils.go (about) 1 package testutil // import "github.com/docker/docker/testutil" 2 3 import "math/rand" 4 5 // GenerateRandomAlphaOnlyString generates an alphabetical random string with length n. 6 func GenerateRandomAlphaOnlyString(n int) string { 7 // make a really long string 8 letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 9 b := make([]byte, n) 10 for i := range b { 11 b[i] = letters[rand.Intn(len(letters))] //nolint: gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) 12 } 13 return string(b) 14 }