stop using deprecated functions from the math/rand package

This commit is contained in:
Marten Seemann 2023-08-21 11:20:07 +07:00
parent bca0ec4f9c
commit d50cf4eb64
8 changed files with 26 additions and 23 deletions

View File

@ -3,9 +3,9 @@ package splitstore
import (
"context"
"crypto/rand"
"errors"
"fmt"
"math/rand"
"sync"
"sync/atomic"
"testing"

View File

@ -3,13 +3,14 @@ package messagepool
import (
"math"
"math/rand"
"testing"
"time"
"golang.org/x/exp/rand"
)
func TestBlockProbability(t *testing.T) {
//stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_001
// stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_001
mp := &MessagePool{}
bp := mp.blockProbabilities(1 - 0.15)
t.Logf("%+v\n", bp)
@ -22,8 +23,8 @@ func TestBlockProbability(t *testing.T) {
}
func TestWinnerProba(t *testing.T) {
//stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_002
rand.Seed(time.Now().UnixNano())
// stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_002
rand.Seed(uint64(time.Now().UnixNano()))
const N = 1000000
winnerProba := noWinnersProb()
sum := 0

View File

@ -4,9 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"os"
"golang.org/x/exp/rand"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -145,7 +145,9 @@ func MakeUnsignedMessageVectors() []vectors.UnsignedMessageVector {
}
params := make([]byte, 32)
rand.Read(params)
if _, err := rand.Read(params); err != nil {
panic(err)
}
msg := &types.Message{
To: to,

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"math/big"
"math/rand"
"os"
"path/filepath"
"sync"
@ -23,6 +22,7 @@ import (
"github.com/minio/blake2b-simd"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
"golang.org/x/exp/rand"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -30,7 +30,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
prooftypes "github.com/filecoin-project/go-state-types/proof"
adt "github.com/filecoin-project/specs-actors/v6/actors/util/adt"
"github.com/filecoin-project/specs-actors/v6/actors/util/adt"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/blockstore"
@ -546,7 +546,7 @@ var sealBenchCmd = &cli.Command{
}
var challenge [32]byte
rand.Read(challenge[:])
_, _ = rand.Read(challenge[:])
beforePost := time.Now()
@ -776,7 +776,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par
start := time.Now()
log.Infof("[%d] Writing piece into sector...", i)
r := rand.New(rand.NewSource(100 + int64(i)))
r := rand.New(rand.NewSource(100 + uint64(i)))
pi, err := sb.AddPiece(context.TODO(), sid, nil, abi.PaddedPieceSize(sectorSize).Unpadded(), r)
if err != nil {

View File

@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"runtime"
@ -17,6 +16,7 @@ import (
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
"golang.org/x/exp/rand"
"golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
@ -33,7 +33,7 @@ import (
)
func init() {
logging.SetLogLevel("*", "DEBUG") //nolint: errcheck
logging.SetLogLevel("*", "DEBUG") // nolint: errcheck
}
var sealProofType = abi.RegisteredSealProof_StackedDrg2KiBV1
@ -50,8 +50,8 @@ type seal struct {
func data(sn abi.SectorNumber, dlen abi.UnpaddedPieceSize) io.Reader {
return io.MultiReader(
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(123)),
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(dlen-123)),
io.LimitReader(rand.New(rand.NewSource(42+uint64(sn))), int64(123)),
io.LimitReader(rand.New(rand.NewSource(42+uint64(sn))), int64(dlen-123)),
)
}
@ -960,7 +960,7 @@ func TestMulticoreSDR(t *testing.T) {
func TestPoStChallengeAssumptions(t *testing.T) {
var r [32]byte
rand.Read(r[:])
_, _ = rand.Read(r[:])
r[31] &= 0x3f
// behaves like a pure function

View File

@ -3,11 +3,11 @@ package fr32_test
import (
"bytes"
"io"
"math/rand"
"os"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/exp/rand"
ffi "github.com/filecoin-project/filecoin-ffi"
commpffi "github.com/filecoin-project/go-commp-utils/ffiwrapper"
@ -72,7 +72,7 @@ func TestPadChunkFFI(t *testing.T) {
func TestPadChunkRandEqFFI(t *testing.T) {
for i := 0; i < 200; i++ {
var input [127]byte
rand.Read(input[:])
_, _ = rand.Read(input[:])
var buf [128]byte
@ -109,7 +109,7 @@ func TestRoundtrip(t *testing.T) {
func TestRoundtripChunkRand(t *testing.T) {
for i := 0; i < 200; i++ {
var input [127]byte
rand.Read(input[:])
_, _ = rand.Read(input[:])
var buf [128]byte
copy(buf[:], input[:])
@ -127,7 +127,7 @@ func TestRoundtrip16MRand(t *testing.T) {
up := abi.PaddedPieceSize(16 << 20).Unpadded()
input := make([]byte, up)
rand.Read(input[:])
_, _ = rand.Read(input[:])
buf := make([]byte, 16<<20)

View File

@ -6,11 +6,11 @@ import (
"crypto/sha256"
"fmt"
"io"
"math/rand"
"sync"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"golang.org/x/exp/rand"
"golang.org/x/xerrors"
"github.com/filecoin-project/dagstore/mount"

View File

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"math/rand"
"net"
"net/http"
"os"
@ -17,6 +16,7 @@ import (
ds_sync "github.com/ipfs/go-datastore/sync"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
"golang.org/x/exp/rand"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-statestore"
@ -195,7 +195,7 @@ type pieceProviderTestHarness struct {
func generatePieceData(size uint64) []byte {
bz := make([]byte, size)
rand.Read(bz)
_, _ = rand.Read(bz)
return bz
}