From 208e49ce4bd230e342653ec7344e61a6668fb5ce Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 1 Dec 2023 16:31:51 +0000 Subject: [PATCH] fs: update use of math/rand to modern practice --- backend/onedrive/quickxorhash/quickxorhash_test.go | 6 ++++-- fstest/fstest.go | 4 +--- vfs/test_vfs/test_vfs.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/onedrive/quickxorhash/quickxorhash_test.go b/backend/onedrive/quickxorhash/quickxorhash_test.go index 40539439d..c38c4d88b 100644 --- a/backend/onedrive/quickxorhash/quickxorhash_test.go +++ b/backend/onedrive/quickxorhash/quickxorhash_test.go @@ -1,10 +1,10 @@ package quickxorhash import ( + "crypto/rand" "encoding/base64" "fmt" "hash" - "math/rand" "testing" "github.com/stretchr/testify/assert" @@ -171,7 +171,9 @@ var _ hash.Hash = (*quickXorHash)(nil) func BenchmarkQuickXorHash(b *testing.B) { b.SetBytes(1 << 20) buf := make([]byte, 1<<20) - rand.Read(buf) + n, err := rand.Read(buf) + require.NoError(b, err) + require.Equal(b, len(buf), n) h := New() b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/fstest/fstest.go b/fstest/fstest.go index 9a3f75753..8a6e9e918 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "log" - "math/rand" "os" "path" "path/filepath" @@ -52,8 +51,7 @@ var ( // Seed the random number generator func init() { - rand.Seed(time.Now().UnixNano()) - + _ = random.Seed() } // Initialise rclone for testing diff --git a/vfs/test_vfs/test_vfs.go b/vfs/test_vfs/test_vfs.go index 53a8208f1..3e70ce1cb 100644 --- a/vfs/test_vfs/test_vfs.go +++ b/vfs/test_vfs/test_vfs.go @@ -31,7 +31,7 @@ var ( // Seed the random number generator func init() { - rand.Seed(time.Now().UnixNano()) + _ = random.Seed() }