Files
moby/internal/testutil/stringutils.go
Sebastiaan van Stijn 67e7274c95 internal/testutil: cleanup GenerateRandomAlphaOnlyString
- use math/rand/v2
- change the util to only produce lowercase; some tests only could
  use lowercase, and we don't need uppercase here, as long as it's
  random.
- drop the Uniqueness test; it was effectively just testing stdlib
  functionality (math/rand/v2 to be random).
- rename to RandomAlpha while we had to update call-sites

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-18 13:05:17 +02:00

15 lines
420 B
Go

package testutil
import "math/rand/v2"
const letters = "abcdefghijklmnopqrstuvwxyz"
// RandomAlpha generates a lowercase alphabetical random string with length n.
func RandomAlpha(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.IntN(len(letters))] // #nosec G404 -- ignore "Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand)"
}
return string(b)
}