Revert "stop using deprecated functions from the math/rand package"

This reverts commit d50cf4eb64.
This commit is contained in:
Marten Seemann 2023-08-21 15:02:06 +07:00
parent d50cf4eb64
commit 93f95d2ef9
8 changed files with 23 additions and 26 deletions

View File

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

View File

@ -3,14 +3,13 @@ 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)
@ -23,8 +22,8 @@ func TestBlockProbability(t *testing.T) {
}
func TestWinnerProba(t *testing.T) {
// stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_002
rand.Seed(uint64(time.Now().UnixNano()))
//stm: @OTHER_IMPLEMENTATION_BLOCK_PROB_002
rand.Seed(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,9 +145,7 @@ func MakeUnsignedMessageVectors() []vectors.UnsignedMessageVector {
}
params := make([]byte, 32)
if _, err := rand.Read(params); err != nil {
panic(err)
}
rand.Read(params)
msg := &types.Message{
To: to,

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"math/big"
"math/rand"
"os"
"path/filepath"
"sync"
@ -22,7 +23,6 @@ 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"
"github.com/filecoin-project/specs-actors/v6/actors/util/adt"
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 + uint64(i)))
r := rand.New(rand.NewSource(100 + int64(i)))
pi, err := sb.AddPiece(context.TODO(), sid, nil, abi.PaddedPieceSize(sectorSize).Unpadded(), r)
if err != nil {

View File

@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"runtime"
@ -16,7 +17,6 @@ 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+uint64(sn))), int64(123)),
io.LimitReader(rand.New(rand.NewSource(42+uint64(sn))), int64(dlen-123)),
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(123)),
io.LimitReader(rand.New(rand.NewSource(42+int64(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,6 +4,7 @@ import (
"bytes"
"context"
"io"
"math/rand"
"net"
"net/http"
"os"
@ -16,7 +17,6 @@ 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
}