Explorar o código

integration-cli: seed rand in makeRandomString

Current uses of `makeRandomString` is to create really
long strings. In #10794, I used them to create nearly-unique
unix paths for the daemon. Although collions are harmless and
don't fail the tests, this prevents the same strings from being
created consistently in every run by seeding rand.Random.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
Ahmet Alp Balkan %!s(int64=10) %!d(string=hai) anos
pai
achega
00cd214afe
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      integration-cli/utils.go

+ 2 - 1
integration-cli/utils.go

@@ -235,8 +235,9 @@ func makeRandomString(n int) string {
 	// make a really long string
 	// make a really long string
 	letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
 	letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
 	b := make([]byte, n)
 	b := make([]byte, n)
+	r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
 	for i := range b {
 	for i := range b {
-		b[i] = letters[rand.Intn(len(letters))]
+		b[i] = letters[r.Intn(len(letters))]
 	}
 	}
 	return string(b)
 	return string(b)
 }
 }