all: remove deprecated uses of math.rand (#26710)

This PR is a (superior) alternative to https://github.com/ethereum/go-ethereum/pull/26708, it handles deprecation, primarily two specific cases. 

`rand.Seed` is typically used in two ways
- `rand.Seed(time.Now().UnixNano())` -- we seed it, just to be sure to get some random, and not always get the same thing on every run. This is not needed, with global seeding, so those are just removed. 
- `rand.Seed(1)` this is typically done to ensure we have a stable test. If we rely on this, we need to fix up the tests to use a deterministic prng-source. A few occurrences like this has been replaced with a proper custom source. 

`rand.Read` has been replaced by `crypto/rand`.`Read` in this PR.
This commit is contained in:
Martin Holst Swende
2023-02-16 14:36:58 -05:00
committed by GitHub
parent e9d42499bb
commit 4d3525610e
28 changed files with 75 additions and 75 deletions
+1 -10
View File
@@ -20,10 +20,9 @@
package signify
import (
"math/rand"
"crypto/rand"
"os"
"testing"
"time"
"github.com/jedisct1/go-minisign"
)
@@ -41,8 +40,6 @@ func TestSignify(t *testing.T) {
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
rand.Seed(time.Now().UnixNano())
data := make([]byte, 1024)
rand.Read(data)
tmpFile.Write(data)
@@ -85,8 +82,6 @@ func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
rand.Seed(time.Now().UnixNano())
data := make([]byte, 1024)
rand.Read(data)
tmpFile.Write(data)
@@ -110,8 +105,6 @@ func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
rand.Seed(time.Now().UnixNano())
data := make([]byte, 1024)
rand.Read(data)
tmpFile.Write(data)
@@ -135,8 +128,6 @@ func TestSignifyTrustedCommentEmpty(t *testing.T) {
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
rand.Seed(time.Now().UnixNano())
data := make([]byte, 1024)
rand.Read(data)
tmpFile.Write(data)