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 ( import (
"context" "context"
"crypto/rand"
"errors" "errors"
"fmt" "fmt"
"math/rand"
"sync" "sync"
"sync/atomic" "sync/atomic"
"testing" "testing"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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