From 1593aae62dd56bfbc414b1a82f4c3d775f6f1752 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 6 Feb 2023 01:01:17 +0000 Subject: [PATCH] math/rand.Read deprecated. --- vfs.go | 4 ++-- vfs_test.go | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/vfs.go b/vfs.go index b482c54..90185ea 100644 --- a/vfs.go +++ b/vfs.go @@ -2,10 +2,10 @@ package sqlite3 import ( "context" + "crypto/rand" "errors" "io" "io/fs" - "math/rand" "os" "path/filepath" "runtime" @@ -79,7 +79,7 @@ func vfsLocaltime(ctx context.Context, mod api.Module, t uint64, pTm uint32) uin func vfsRandomness(ctx context.Context, mod api.Module, pVfs, nByte, zByte uint32) uint32 { mem := memory{mod}.view(zByte, nByte) - n, _ := rand.Read(mem) + n, _ := rand.Reader.Read(mem) return uint32(n) } diff --git a/vfs_test.go b/vfs_test.go index 1e24369..61d4b94 100644 --- a/vfs_test.go +++ b/vfs_test.go @@ -5,7 +5,6 @@ import ( "context" "errors" "io/fs" - "math/rand" "os" "path/filepath" "testing" @@ -59,18 +58,14 @@ func Test_vfsLocaltime(t *testing.T) { func Test_vfsRandomness(t *testing.T) { mem := newMemory(128) - rand.Seed(0) rc := vfsRandomness(context.TODO(), mem.mod, 0, 16, 4) if rc != 16 { t.Fatal("returned", rc) } - var want [16]byte - rand.Seed(0) - rand.Read(want[:]) - - if got := mem.view(4, 16); !bytes.Equal(got, want[:]) { - t.Errorf("got %q, want %q", got, want) + var zero [16]byte + if got := mem.view(4, 16); bytes.Equal(got, zero[:]) { + t.Fatal("all zero") } }