Remove unnecessary calls to rand.Seed(time.Now().Unix()).

As per https://pkg.go.dev/math/rand#Seed:
"If Seed is not called, the generator is seeded randomly at program startup."
"Prior to Go 1.20, the generator was seeded like Seed(1) at program startup. To
force the old behavior, call Seed(1) at program startup."
"As of Go 1.20 there is no reason to call Seed with a random value."

rand.Seed() is deprecated. Followup to #11015.

PiperOrigin-RevId: 685052229
This commit is contained in:
Ayush Ranjan
2024-10-11 20:19:04 -07:00
committed by gVisor bot
parent 72846ff97c
commit a81ec225dc
9 changed files with 0 additions and 33 deletions
-2
View File
@@ -154,8 +154,6 @@ func doTest(t harness, opts testOpts) {
var hashKey = []byte("01234567890123456789012345678901")
func TestCompress(t *testing.T) {
rand.Seed(time.Now().Unix())
var (
data = initTest(t, 10*1024*1024)
data0 = data[:0]
-4
View File
@@ -18,14 +18,10 @@ import (
"bytes"
"fmt"
"io"
"math/rand"
"testing"
"time"
)
func TestNoCompress(t *testing.T) {
rand.Seed(time.Now().Unix())
var (
data = initTest(t, 10*1024*1024)
data0 = data[:0]
-3
View File
@@ -22,7 +22,6 @@ import (
"math/rand"
"runtime"
"testing"
"time"
"gvisor.dev/gvisor/pkg/compressio"
)
@@ -44,8 +43,6 @@ type testCase struct {
}
func TestStatefile(t *testing.T) {
rand.Seed(time.Now().Unix())
compression := map[string]CompressionLevel{
"none": CompressionLevelNone,
"compressed": CompressionLevelFlateBestSpeed,
-4
View File
@@ -45,11 +45,9 @@ import (
"bytes"
"fmt"
"log"
"math/rand"
"net"
"os"
"strconv"
"time"
"gvisor.dev/gvisor/pkg/rawfile"
"gvisor.dev/gvisor/pkg/tcpip"
@@ -100,8 +98,6 @@ func main() {
remoteAddrName := os.Args[4]
remotePortName := os.Args[5]
rand.Seed(time.Now().UnixNano())
addr := tcpip.AddrFromSlice(net.ParseIP(addrName).To4())
remote := tcpip.FullAddress{
NIC: 1,
-4
View File
@@ -25,12 +25,10 @@ import (
"flag"
"io"
"log"
"math/rand"
"net"
"os"
"strconv"
"strings"
"time"
"gvisor.dev/gvisor/pkg/rawfile"
"gvisor.dev/gvisor/pkg/tcpip"
@@ -113,8 +111,6 @@ func main() {
addrName := flag.Arg(1)
portName := flag.Arg(2)
rand.Seed(time.Now().UnixNano())
// Parse the mac address.
maddr, err := net.ParseMAC(*mac)
if err != nil {
-6
View File
@@ -19,7 +19,6 @@ import (
"encoding/json"
"errors"
"fmt"
mrand "math/rand"
"os"
"runtime"
"strconv"
@@ -294,11 +293,6 @@ type FDMapping struct {
Host int
}
func init() {
// Initialize the random number generator.
mrand.Seed(gtime.Now().UnixNano())
}
// Args are the arguments for New().
type Args struct {
// Id is the sandbox ID.
-1
View File
@@ -41,7 +41,6 @@ import (
func init() {
log.SetLevel(log.Debug)
rand.Seed(time.Now().UnixNano())
if err := fsgofer.OpenProcSelfFD("/proc/self/fd"); err != nil {
panic(err)
}
-4
View File
@@ -398,10 +398,6 @@ func main() {
if *forward == "" {
log.Fatalf("no forward provided")
}
// Seed the random number generator to ensure that we are given MAC addresses that don't
// for the case of the client and server stack.
rand.Seed(time.Now().UTC().UnixNano())
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
-5
View File
@@ -24,17 +24,12 @@ import (
"strconv"
"strings"
"testing"
"time"
"github.com/docker/docker/api/types/mount"
"gvisor.dev/gvisor/pkg/test/dockerutil"
"gvisor.dev/gvisor/pkg/test/testutil"
)
func init() {
rand.Seed(int64(time.Now().Nanosecond()))
}
func TestMain(m *testing.M) {
dockerutil.EnsureSupportedDockerVersion()
flag.Parse()