소스 검색

Remove use of deprecated rand.Read

Using the global rand source is deprecated since go 1.20, so instead we
make an explicit local one with a fixed seed

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis 1 년 전
부모
커밋
bd8c8089a5
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      plugins/allocators/ipcalc_test.go

+ 3 - 1
plugins/allocators/ipcalc_test.go

@@ -57,8 +57,10 @@ func ExampleAddPrefixes() {
 
 // Offset is used as a hash function, so it needs to be reasonably fast
 func BenchmarkOffset(b *testing.B) {
+	// Need predictable randomness for benchmark reproducibility
+	rng := rand.New(rand.NewSource(0))
 	addresses := make([]byte, b.N*net.IPv6len*2)
-	_, err := rand.Read(addresses)
+	_, err := rng.Read(addresses)
 	if err != nil {
 		b.Fatalf("Could not generate random addresses: %v", err)
 	}