mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-17 04:36:11 +00:00
libs/rand: remove custom seed function (#7473)
This commit is contained in:
@@ -5,13 +5,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
mrand "math/rand"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmprotobits "github.com/tendermint/tendermint/proto/tendermint/libs/bits"
|
||||
)
|
||||
|
||||
@@ -25,8 +24,6 @@ type BitArray struct {
|
||||
// NewBitArray returns a new bit array.
|
||||
// It returns nil if the number of bits is zero.
|
||||
func NewBitArray(bits int) *BitArray {
|
||||
// Reseed non-deterministically.
|
||||
tmrand.Reseed()
|
||||
if bits <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -270,8 +267,14 @@ func (bA *BitArray) PickRandom() (int, bool) {
|
||||
if len(trueIndices) == 0 { // no bits set to true
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// NOTE: using the default math/rand might result in somewhat
|
||||
// amount of determinism here. It would be possible to use
|
||||
// rand.New(rand.NewSeed(time.Now().Unix())).Intn() to
|
||||
// counteract this possibility if it proved to be material.
|
||||
//
|
||||
// nolint:gosec // G404: Use of weak random number generator
|
||||
return trueIndices[mrand.Intn(len(trueIndices))], true
|
||||
return trueIndices[rand.Intn(len(trueIndices))], true
|
||||
}
|
||||
|
||||
func (bA *BitArray) getTrueIndices() []int {
|
||||
|
||||
Reference in New Issue
Block a user