libs/rand: remove custom seed function (#7473)

This commit is contained in:
Sam Kleinman
2021-12-17 12:15:27 -05:00
committed by GitHub
parent ff615dda66
commit 9a0dbdbf13
3 changed files with 11 additions and 51 deletions
+8 -5
View File
@@ -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 {