math/rand.Read deprecated.

This commit is contained in:
Nuno Cruces
2023-02-06 01:01:17 +00:00
parent 0b184851d3
commit 1593aae62d
2 changed files with 5 additions and 10 deletions

4
vfs.go
View File

@@ -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)
}

View File

@@ -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")
}
}