Skip to content

Commit

Permalink
stop using deprecated functions from the math/rand package
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 21, 2023
1 parent bca0ec4 commit dbad439
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion blockstore/splitstore/splitstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package splitstore

import (
"context"
"crypto/rand"
"errors"
"fmt"
"math/rand"
"sync"
"sync/atomic"
"testing"
Expand Down
9 changes: 5 additions & 4 deletions chain/messagepool/block_proba_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions chain/vectors/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"math/big"
"math/rand"
"os"
"path/filepath"
"sync"
Expand All @@ -23,14 +22,15 @@ 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"
"github.com/filecoin-project/go-paramfetch"
"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"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions storage/sealer/ffiwrapper/sealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"runtime"
Expand All @@ -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"
Expand All @@ -33,7 +33,7 @@ import (
)

func init() {
logging.SetLogLevel("*", "DEBUG") //nolint: errcheck
logging.SetLogLevel("*", "DEBUG") // nolint: errcheck
}

var sealProofType = abi.RegisteredSealProof_StackedDrg2KiBV1
Expand All @@ -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)),
)
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions storage/sealer/fr32/fr32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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[:])
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion storage/sealer/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions storage/sealer/piece_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"math/rand"
"net"
"net/http"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -195,7 +195,7 @@ type pieceProviderTestHarness struct {

func generatePieceData(size uint64) []byte {
bz := make([]byte, size)
rand.Read(bz)
_, _ = rand.Read(bz)
return bz
}

Expand Down

0 comments on commit dbad439

Please sign in to comment.